Difficulty: Easy
Correct Answer: eval
Explanation:
Introduction / Context:
Python distinguishes between language keywords and built in functions. Keywords are reserved words that have special syntactic meaning and cannot be used as identifiers. Built in functions, on the other hand, are regular names defined in the built in namespace that can be shadowed or reassigned, although doing so is not recommended. This question checks whether you can recognise which names are true keywords.
Given Data / Assumptions:
Concept / Approach:
Keywords such as assert, pass and nonlocal are part of Python syntax. assert is used for debug style checks, pass for empty blocks and nonlocal for referencing variables in an enclosing scope in nested functions. eval, however, is not a keyword. It is a built in function that evaluates a string as a Python expression. Because eval is a normal identifier, you can technically assign another value to eval in your code, although doing so will hide the built in function and is usually a bad idea.
Step-by-Step Solution:
Step 1: Identify which names are recognised as keywords by the Python interpreter.Step 2: assert is a keyword used for runtime assertions, so it is reserved.Step 3: pass is a keyword that acts as a no operation statement.Step 4: nonlocal is a keyword used inside nested functions to refer to variables in an enclosing but non global scope.Step 5: eval is provided as a built in function, not as a keyword, so option C is the only name in the list that is not a keyword.
Verification / Alternative check:
In a Python interpreter, you can run an instruction such as import keyword; print("eval" in keyword.kwlist). The result will be False, showing that eval is not in the keyword list. By contrast, "assert", "pass" and "nonlocal" all appear in keyword.kwlist. You can also assign eval = 5 in code, which is allowed for a function name but not for keywords like pass or assert, which cannot be used as variable names.
Why Other Options Are Wrong:
Option A, assert, is a true keyword and is documented as part of the language syntax. Option B, pass, is used whenever a statement is required syntactically but no action is needed. Option D, nonlocal, is also a keyword and plays a role in closures. None of these can be used freely as identifiers.
Common Pitfalls:
Beginners sometimes confuse the status of built in functions and assume that any name they often see in examples must be a keyword. This confusion can lead to accidental shadowing of built in functions, which causes surprising behaviour. A good practice is to check the official keyword list if you are unsure and to avoid reusing names of common built in functions even though it is technically allowed.
Final Answer:
eval
Discussion & Comments