Last modified: Apr 22, 2026 By Alexander Williams

Python Keywords & Reserved Words List Guide

Every programming language has a set of special words. These words have a predefined meaning and purpose. In Python, these are called keywords or reserved words.

You cannot use them for variable names, function names, or any other identifiers. Knowing them is essential for writing correct Python code.

What Are Python Keywords?

Keywords are the building blocks of the Python language. They define the syntax and structure of your code.

The Python interpreter recognizes these words and understands the specific action they represent. Because of this, they are "reserved" for the language itself.

Trying to use a keyword as a variable name will cause a SyntaxError. This stops your code from running.


# This will cause an error because 'for' is a keyword.
for = 10
    

SyntaxError: invalid syntax
    

How to View Python's Keyword List

You don't need to memorize all keywords. Python provides a built-in way to see them. Use the keyword module.


import keyword

# Print the full list of keywords
print(keyword.kwlist)

# Check if a word is a keyword
print(keyword.iskeyword("if"))   # Output: True
print(keyword.iskeyword("city")) # Output: False
    

['False', 'None', 'True', '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']
    

The Complete List of Python Keywords (Python 3.11+)

Python 3.11 has 35 reserved keywords. Let's group them by their primary function.

Value Keywords: True, False, None

These represent constant values in Python.

True and False are the two Boolean truth values. None represents the absence of a value.


is_active = True
result = None

if is_active:
    print("Proceed")  # This will print
    

Operator Keywords: and, or, not, is, in

These keywords are used to make logical comparisons and check membership.

and, or, not are logical operators. is checks object identity. in checks if an item exists in a sequence like a Python list.


x = 5
my_list = [1, 2, 3, 4, 5]

if x > 0 and x in my_list:
    print("Positive and in list")

if x is not None:
    print("x has a value")
    

Control Flow Keywords

These keywords dictate the order in which your code executes.

Conditionals:if, elif, else

Loops:for, while, break, continue


# if, elif, else
score = 85
if score >= 90:
    grade = 'A'
elif score >= 80:
    grade = 'B'  # This assignment happens
else:
    grade = 'C'
print(f"Grade: {grade}")

# for loop with break
for num in range(10):
    if num == 5:
        break  # Stops the loop completely
    print(num)
    

Grade: B
0
1
2
3
4
    

Structure Keywords

These define the core structures of your program: functions, classes, and modules.

Functions & Methods:def, return, lambda, yield

Classes:class

Modules:import, from, as


# def and return
def calculate_area(length, width):
    """Calculate the area of a rectangle."""
    return length * width

# lambda (anonymous function)
square = lambda x: x * x
print(square(4))  # Output: 16

# import and as
import math as m
print(m.sqrt(25))  # Output: 5.0
    

Variable Scope Keywords

These control where a variable is accessible.

global declares a variable in the global scope. nonlocal is used in nested functions to modify a variable in the enclosing (non-global) scope.


count = 10  # Global variable

def update_counter():
    global count  # Use the global 'count'
    count += 5
    print(f"Inside function: {count}")

update_counter()
print(f"Outside function: {count}")
    

Inside function: 15
Outside function: 15
    

Exception Handling Keywords

Python uses these keywords to handle errors gracefully. This prevents your program from crashing.

try, except, finally, raise, assert


try:
    number = int(input("Enter a number: "))
    result = 10 / number
    print(f"Result: {result}")
except ZeroDivisionError:
    print("You cannot divide by zero!")  # Handles a specific error
except ValueError:
    print("Please enter a valid number.") # Handles another error
finally:
    print("This always runs.")  # Clean-up code
    

Other Important Keywords

del: Deletes a variable or an item from a list or dictionary.

pass: A null operation. It's a placeholder where syntax requires a statement but you want no action.

with: Used for context management, commonly when working with files. It ensures resources are properly closed.

async, await: Used for writing asynchronous code.


# del keyword
items = ['apple', 'banana', 'cherry']
del items[1]  # Removes 'banana' from the list
print(items)  # Output: ['apple', 'cherry']

# pass keyword
def future_function():
    pass  # To be implemented later

# with keyword
with open('file.txt', 'r') as file:
    content = file.read()
# File is automatically closed here
    

Common Mistakes and Best Practices

Mistake 1: Using a keyword as a name. This is the most common error for beginners.

Solution: Choose a different, descriptive name. For example, use user_list instead of list.

Mistake 2: Misspelling keywords. flase instead of False will cause a NameError.

Solution: Use a code editor with syntax highlighting. Misspelled keywords won't be colored correctly.

Best Practice: Understand the purpose of each keyword. Don't just memorize the list. Knowing what yield does is more important than knowing it's a keyword.

Conclusion

Python's 35 keywords are the foundation of the language. They control logic, define structure, and handle errors.

You cannot use them as names in your code. Use the keyword module to check them.

Focus on learning their functions in groups. Start with control flow (if, for), then move to structure (def, class).

Understanding these reserved words is a major step towards writing clean, effective, and error-free Python programs. As you work more with data structures, you'll use these keywords to manage lists, sets, and other collections effectively.