Nearby lessons

13 of 159

Python - Reserved Words

📌 What You Will Learn
  • 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.

Loading editor…

2. Special Value

None represents the absence of a value.

Loading editor…

3. Logical Keywords

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

Loading editor…

4. Conditional Keywords

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

Loading editor…

5. Looping Keywords

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

Loading editor…

6. Exception Handling Keywords

Python provides keywords to handle runtime errors.

Loading editor…

7. Import Keywords

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

Loading editor…

8. Asynchronous Programming Keywords

The keywords async and await are used for asynchronous programming.

Loading editor…

9. OOP and Function Keywords

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

Loading editor…

10. Variable Scope Keywords

The keywords global and nonlocal control variable scope.

Loading editor…

11. Delete Keyword

The del keyword is used to delete variables or objects.

Loading editor…

12. Context Management Keyword

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

Loading editor…

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.

Loading editor…

Invalid Use of Reserved Words

Reserved words cannot be used as identifiers.

Loading editor…

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
📝 Key Takeaways
  • 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

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.