PCAP-31-03 practice question 16 of 25

Which of the following words can be used as a variable name? (Select two valid names)

Full set: 147 questions
Answer options
A: for
B: True
C: true Correct answer
D: For Correct answer
Correct Answer:
C. true; D. For
Explanation

An identifier in Python must start with a letter or underscore and must not be a reserved keyword or a Boolean literal (Language Reference § 2.3). “true” and “For” satisfy the lexical rules and are not reserved; “for” is a keyword and “True” is the Boolean literal, so both are forbidden.

Why Incorrect

A – ‘for’ is a reserved keyword. B – ‘True’ is the Boolean constant, reserved and immutable.

References

1. Python Software Foundation. “Lexical Analysis”, § 2.3 Identifiers and keywords (https://docs.python.org/3/reference/lexicalanalysis.html#identifiers).

2. Stanford CS41, “Python Style & Idioms”, slide 6 – Reserved words list.

Scroll to Top