Python Keywords (original) (raw)

Last Updated : 23 Jun, 2025

Keywords in Python are reserved words that have special meanings and serve specific purposes in the language syntax. Python keywords cannot be used as the names of variables, functions, and classes or any other identifier.

Getting List of all Python keywords

We can also get all the keyword names using the below code.

Python `

import keyword

printing all keywords at once using "kwlist()"

print("The list of keywords is : ") print(keyword.kwlist)

`

**Output:

The list of keywords are:
['False', 'None', 'True',"__peg_parser__ 'and', 'as', 'assert', 'async', 'await', 'break',
'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

How to Identify Python Keywords ?

Let's categorize all keywords based on context for a more clear understanding.

**Category **Keywords
**Value Keywords True, False, None
**Operator Keywords and, or, not, is, in
**Control Flow Keywords if, else, elif, for, while, break, continue, pass, try, except, finally, raise, assert
**Function and Class def, return, lambda, yield, class
**Context Management with, as
**Import and Module import, from
**Scope and Namespace global, nonlocal
**Async Programming async, await

Difference Between Keywords and Identifiers

Keywords **Identifiers
Reserved words in Python that have a specific meaning. Names given to variables, functions, classes, etc.
Cannot be used as variable names. Can be used as variable names (if not a keyword).
Examples: if, else, for, while Examples: x, number, sum, result
Part of the Python syntax. User-defined, meaningful names in the code.
They cannot be redefined or changed. Can be defined and redefined by the programmer.

Difference Between Variables and Keywords

**Variables **Keywords
Used to store data. Reserved words with predefined meanings in Python.
Can be created, modified, and deleted by the programmer. Cannot be modified or used as variable names.
Examples: x, age, name Examples: if, while, for
Hold values that are manipulated in the program. Used to define the structure of Python code.
Variable names must follow naming rules but are otherwise flexible. Fixed by Python language and cannot be altered.