Nearby lessons
13 of 159Python - Reserved Words
- Know what reserved words are in Python
- Understand why you cannot use them as identifiers
- Learn all 35 Python reserved words
Introduction
In Python, some words have a predefined meaning.
These words are called Reserved Words or Keywords.
Python uses these keywords for specific programming tasks, so they cannot be used as identifiers.
You cannot use reserved words as:
- Variable names
- Function names
- Class names
- Module names
- Other identifiers
Total Reserved Words
Python 3.14 contains 35 reserved words (keywords).
Python also provides four soft keywords:
- match
- case
- _
- type
Soft keywords behave like keywords only in specific situations and are not included in the reserved keyword list.
List of Python Reserved Words
| Reserved Words |
|---|
| True, False, None |
| and, or, not, is |
| if, elif, else |
| while, for, break, continue, return |
| in, yield |
| try, except, finally, raise, assert |
| import, from, as |
| class, def, pass, lambda |
| global, nonlocal |
| del, with |
| async, await |
1. Boolean Keywords
True and False represent Boolean values.
2. Special Value
None represents the absence of a value.
3. Logical Keywords
The keywords and, or, not, and is are used in logical expressions.
4. Conditional Keywords
The keywords if, elif, and else are used for decision making.
5. Looping Keywords
The keywords for, while, break, continue, return, in, and yield are used in loops and iteration.
6. Exception Handling Keywords
Python provides keywords to handle runtime errors.
7. Import Keywords
The keywords import, from, and as are used to import modules.
8. Asynchronous Programming Keywords
The keywords async and await are used for asynchronous programming.
9. OOP and Function Keywords
The keywords class, def, pass, and lambda are used in object-oriented programming and function definitions.
10. Variable Scope Keywords
The keywords global and nonlocal control variable scope.
11. Delete Keyword
The del keyword is used to delete variables or objects.
12. Context Management Keyword
The with keyword is used for resource management, such as working with files.
Important Notes
- All reserved words contain only alphabet characters.
True,False, andNonebegin with capital letters.- All other reserved words are written in lowercase.
asyncandawaitwere introduced in Python 3.5.match,case,_, andtypeare soft keywords.
Display All Reserved Words
Python provides the keyword module to display all reserved words.
Invalid Use of Reserved Words
Reserved words cannot be used as identifiers.
Key Points
- Python 3.14 contains 35 reserved words.
- Reserved words have predefined meanings.
- They cannot be used as variable names or other identifiers.
True,False, andNonestart with capital letters.- Most other keywords are written in lowercase.
- The
keywordmodule displays the list of reserved words.
Quick Summary
| Category | Examples |
|---|---|
| Boolean Values | True, False |
| Special Value | None |
| Logical Operators | and, or, not, is |
| Conditional Statements | if, elif, else |
| Loops | for, while, break, continue |
| Exception Handling | try, except, finally, raise |
| Import | import, from, as |
| OOP & Functions | class, def, lambda, pass |
| Variable Scope | global, nonlocal |
| Others | del, with, async, await |
- Reserved words have special meaning in Python
- You cannot use them as variable names, function names, or class names
- There are 35 reserved words in Python 3
- Keywords like if, else, for, while, def, class are commonly used
- Always check the official list when in doubt