Python keywords MCQS

Q. Which of the following is NOT a Python keyword?

A
pass
B
eval
C
yield
D
nonlocal
Solution:

eval is a built-in function; the others are keywords.

Q. Which keyword is used to define a function?

A
function
B
def
C
fun
D
define
Solution:

def starts a function definition.

Q. Which keyword is used to define a class?

A
object
B
struct
C
class
D
Class
Solution:

class is lowercase; Python is case-sensitive.

Q. How many keywords does Python 3.12 have?

A
30
B
33
C
35
D
40
Solution:

keyword.kwlist has 35 entries in Python 3.12.

Q. Which of these is a reserved keyword in Python?

A
print
B
main
C
nonlocal
D
self
Solution:

nonlocal is reserved; print is a function, main and self are ordinary names.

Q. Which keywords begin with a capital letter?

A
If, Else
B
True, False, None
C
Class, Def
D
None only
Solution:

True, False and None are the only capitalised keywords.

Q. What does keyword.iskeyword("switch") return?

A
True
B
False
C
SyntaxError
D
None
Solution:

Python has no switch keyword; it uses match-case (soft keywords) instead.

Q. Which statement about soft keywords is correct?

A
They can never be used as variable names
B
They act as keywords only in specific contexts
C
They were removed in Python 3
D
They are the same as built-in functions
Solution:

match, case, _ and type are keywords only in their special syntax and can be ordinary names elsewhere.

Entri PDF Icon

Get Question Bank

Strengthen Your Practice with our comprehensive question bank.