Nearby lessons
13 of 108Python - 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.
main.py
True False
2. Special Value
None represents the absence of a value.
main.py
None
3. Logical Keywords
The keywords and, or, not, and is are used in logical expressions.
main.py
False True False
4. Conditional Keywords
The keywords if, elif, and else are used for decision making.
main.py
Eligible
5. Looping Keywords
The keywords for, while, break, continue, return, in, and yield are used in loops and iteration.
main.py
0 1 2 3 4
6. Exception Handling Keywords
Python provides keywords to handle runtime errors.
main.py
Cannot divide by zero
7. Import Keywords
The keywords import, from, and as are used to import modules.
main.py
4.0
8. Asynchronous Programming Keywords
The keywords async and await are used for asynchronous programming.
main.py
Hello
9. OOP and Function Keywords
The keywords class, def, pass, and lambda are used in object-oriented programming and function definitions.
main.py
Function created successfully.
10. Variable Scope Keywords
The keywords global and nonlocal control variable scope.
main.py
20
11. Delete Keyword
The del keyword is used to delete variables or objects.
main.py
Variable deleted.
12. Context Management Keyword
The with keyword is used for resource management, such as working with files.
main.py
Contents of the file are displayed.
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.
main.py
Displays the complete list of Python reserved words.
Invalid Use of Reserved Words
Reserved words cannot be used as identifiers.
main.py
SyntaxError
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 |