What are Keywords in Python?
Python has a set of reserved words called keywords. These words have predefined meanings and are used to define the syntax and structure of Python code. As of Python 3.11, there are total 36 keywords.
Or in Python, keywords are special reserved words that have specific meanings and purposes in the language. They are used to define the syntax and structure of Python programs. You cannot use keywords as variable names because they are part of the Python language itself.
Note:
You cannot use keywords as variable names, function names, or identifiers because they are reserved by Python.
Example:
class = "Math" # ❌ Invalid: 'class' is a keyword
if = 10 # ❌ Invalid: 'if' is a keyword
Explanation:
In the example above, class
and if
are Python keywords used for class
definitions and conditional statements. Using them as variable names will cause a syntax
error.
List of Python Keywords
Keywords in Python | ||||
---|---|---|---|---|
False | await | else | import | pass |
None | break | except | in | raise |
True | class | finally | is | return |
and | continue | for | lambda | try |
as | def | from | nonlocal | while |
assert | del | global | not | with |
async | elif | if | or | yield |
match | case |
Summary:
- Python keywords are predefined, reserved words with special meanings.
- You cannot use them as variable names.
- They are essential for defining logic, conditions, functions, loops, classes, and more.