PCEP-30-02 · Question #128
Select the true statements: (Choose two.)
The correct answer is C. You cannot use keywords as variable names in Python. Python keywords (like if, for, class, return, etc.) are reserved by the language and cannot be used as variable names - attempting for = 5 raises a SyntaxError immediately, making C correct. By the same rule, D is also correct: keywords are equally forbidden as function names…
Question
Options
- AYou can use keywords as variable names in Python
- BYou can use keywords as function names in Python
- CYou cannot use keywords as variable names in Python
- DYou cannot use keywords as function names in Python
How the community answered
(54 responses)- A4% (2)
- B13% (7)
- C76% (41)
- D7% (4)
Explanation
Python keywords (like if, for, class, return, etc.) are reserved by the language and cannot be used as variable names - attempting for = 5 raises a SyntaxError immediately, making C correct. By the same rule, D is also correct: keywords are equally forbidden as function names, so def if(): is invalid syntax. Options A and B are wrong for the same reason - there is no distinction between variable and function names here; the restriction applies to all identifiers. The memory tip: think of keywords as "taken" parking spots - the Python interpreter has already claimed them for its own grammar, so no user-defined name of any kind can occupy that spot.
Community Discussion
No community discussion yet for this question.