Nearby lessons

13 of 108

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.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
True
False

2. Special Value

None represents the absence of a value.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
None

3. Logical Keywords

The keywords and, or, not, and is are used in logical expressions.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
False
True
False

4. Conditional Keywords

The keywords if, elif, and else are used for decision making.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Eligible

5. Looping Keywords

The keywords for, while, break, continue, return, in, and yield are used in loops and iteration.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
0
1
2
3
4

6. Exception Handling Keywords

Python provides keywords to handle runtime errors.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Cannot divide by zero

7. Import Keywords

The keywords import, from, and as are used to import modules.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
4.0

8. Asynchronous Programming Keywords

The keywords async and await are used for asynchronous programming.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Hello

9. OOP and Function Keywords

The keywords class, def, pass, and lambda are used in object-oriented programming and function definitions.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Function created successfully.

10. Variable Scope Keywords

The keywords global and nonlocal control variable scope.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
20

11. Delete Keyword

The del keyword is used to delete variables or objects.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Variable deleted.

12. Context Management Keyword

The with keyword is used for resource management, such as working with files.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Contents of the file are displayed.

Important Notes

  • All reserved words contain only alphabet characters.
  • True, False, and None begin with capital letters.
  • All other reserved words are written in lowercase.
  • async and await were introduced in Python 3.5.
  • match, case, _, and type are soft keywords.

Display All Reserved Words

Python provides the keyword module to display all reserved words.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Displays the complete list of Python reserved words.

Invalid Use of Reserved Words

Reserved words cannot be used as identifiers.

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
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, and None start with capital letters.
  • Most other keywords are written in lowercase.
  • The keyword module displays the list of reserved words.

Quick Summary

Category Examples
Boolean ValuesTrue, False
Special ValueNone
Logical Operatorsand, or, not, is
Conditional Statementsif, elif, else
Loopsfor, while, break, continue
Exception Handlingtry, except, finally, raise
Importimport, from, as
OOP & Functionsclass, def, lambda, pass
Variable Scopeglobal, nonlocal
Othersdel, with, async, await

🧠 Test Your Knowledge

8 Questions

Progress: 0 / 8
Keep Going!Python - Data Types