Checking your session…
Module 02: Variables, Data Types & Operators

Python Keywords

Level: 1 | Version: v1.0 | Author: Meptrasoft


What is a Keyword?

A keyword is a reserved word that has a fixed, special meaning in Python.

Because keywords are reserved by Python for building code structure, you cannot use keywords as variable names, function names, or class names.

PYTHON
# Incorrect: Using 'if' (a keyword) as a variable name raises a SyntaxError
if = 10        # Wrong

# Correct: Use a normal name
if_value = 10  # Correct

Output:

TEXT
KEYWORD → RESERVED WORD IN PYTHON → CANNOT BE USED AS A VARIABLE NAME

How Many Keywords Are There in Python?

In current Python versions, there are 35 reserved keywords.

You can check the full list of keywords directly in Python using the built-in keyword module:

PYTHON
import keyword

# Print all keywords in your Python version
print(keyword.kwlist)

# Print total count of keywords
print(len(keyword.kwlist))  # Output: 35

You can also check whether any word is a keyword using keyword.iskeyword():

PYTHON
import keyword

print(keyword.iskeyword("for"))    # True (for is a keyword)
print(keyword.iskeyword("total"))  # False (total is a normal variable name)

All 35 Keywords Grouped by Category

The diagram below shows the main keyword groups. The table after it gives a complete beginner-friendly list of all 35 reserved keywords.

Values True False None Conditions if elif else Loops for while break continue Functions def return lambda yield Logic / Membership and or not in is Exceptions try except finally raise
Common Python keywords grouped into major categories.

Here is a complete breakdown of the 35 reserved keywords by category:

Category Keywords What They Do
Values True, False, None Represent Boolean truth values and the absence of a value
Conditions if, elif, else Used for making decisions in code
Loops for, while, break, continue, pass Used to repeat actions or control loop flow
Functions & Classes def, return, lambda, yield, class Used to create functions and classes
Logic & Comparison and, or, not, in, is Used for logical tests and membership checks
Imports & Scope import, from, as, global, nonlocal Used to load modules and manage variable scope
Error Handling try, except, finally, raise, assert Used to handle runtime errors gracefully
Other Control Keywords with, del, async, await Used for context managers, deleting names, and asynchronous programming

Note: Only three keywords start with a capital letter in Python: True, False, and None. All other keywords are written in lowercase.


Placement Quick Points

  • Python has 35 reserved keywords.
  • Keywords cannot be used as variable names.
  • Attempting to use a keyword as a variable name raises a SyntaxError.
  • Only True, False, and None start with a capital letter.
  • Use keyword.kwlist to see the full list of keywords.
  • Use keyword.iskeyword("word") to check if a word is a keyword.

Interview Questions

What is a keyword in Python?
A reserved word that has a fixed, predefined meaning in Python syntax.
Can you use class as a variable name in Python?
No. class is a reserved keyword; using it as a variable name raises a SyntaxError.
Which Python keywords start with a capital letter?
Only three: True, False, and None.
How can you check if a word is a Python keyword using code?
Import the keyword module and use keyword.iskeyword("word").
What error occurs if you use a keyword as a variable name?
SyntaxError: invalid syntax.

Practice

  1. Write a program using import keyword to print all 35 Python keywords.
  2. Check if eval, exec, async, and await are Python keywords using keyword.iskeyword().
  3. Fix the syntax error in this code:
PYTHON
for = "Fourth Year Student"
  1. Name three keywords used for conditional statements.
  2. Name three keywords used for handling exceptions/errors.

End of Python Keywords