Learn What Python Keywords Are: Absolute Beginners Tutorial

Python keywords are reserved words baked into the language itself. They form the skeleton of every Python program you write, controlling flow, defining structure, and expressing logic. Before you can name variables or write functions confidently, you need to know what keywords are, why they exist, and what rules they follow.

Every programming language reserves certain words for its own use. In Python, these are called keywords. When the Python interpreter reads your code, keywords carry specific, unambiguous meaning. That is why you cannot use them as names for anything else — the interpreter would be unable to tell whether you meant the keyword or an identifier.

What Are Python Keywords?

A Python keyword is a word that the language has permanently reserved for a specific purpose. Keywords define the language's grammar. They tell the interpreter what kind of statement or expression is being written. When the interpreter sees if, it knows a conditional is starting. When it sees def, it knows a function definition is beginning.

Keywords cannot be reassigned. You cannot write if = 10 or True = False — both raise a SyntaxError immediately. This restriction is intentional. It keeps the language unambiguous and prevents programs from accidentally breaking core syntax.

Note

Keywords are different from built-in functions like print(), len(), or range(). Built-ins can technically be overridden (though you should never do so). Keywords cannot. The interpreter protects keywords at the grammar level before any code even runs.

You can verify this for yourself at any time using the keyword module in the standard library:

python
import keyword

# Print all reserved keywords
print(keyword.kwlist)

# Check if a word is a keyword
print(keyword.iskeyword('if'))      # True
print(keyword.iskeyword('hello'))   # False

# Check soft keywords (Python 3.9+)
print(keyword.softkwlist)

The output of keyword.kwlist reflects the keywords in your installed Python version, so running this command is always the authoritative way to check.

The Complete List of Python Keywords

As of Python 3.12 and 3.13, there are 35 reserved keywords. The grid below shows all of them. With the exception of True, False, and None, every reserved keyword is written entirely in lowercase.

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
Pro Tip

If you write True as true (lowercase), Python does not raise an error immediately — but true becomes a regular identifier, not a Boolean value. This is a subtle mistake beginners sometimes make. Always capitalize True, False, and None.

code builder click a token to place it

Build a valid Python function definition that returns a greeting. Click each token in the correct order:

your code will appear here...
return class ( def : name import ) greet
Why: A function definition always starts with the keyword def, followed by the function name (greet), then parentheses enclosing any parameters (name), and ends the signature with a colon (:). The body follows on the next line — here just return name. Using class or import here is incorrect because those keywords serve entirely different purposes.

Keyword Categories Explained

Grouping the 35 keywords by their purpose makes them much easier to learn. Rather than memorizing 35 isolated words, you can learn a handful of categories and understand what each group is responsible for. The accordion below covers each category with the keywords it contains and a plain-language description of what they do.

if
Begins a conditional block. The code inside runs only when the condition is true.
elif
Short for "else if". Adds an additional condition to check after a failed if.
else
Runs when all preceding if and elif conditions are false. Also used as the non-exception branch in try/except.
for
Starts a loop that iterates over a sequence or iterable object.
while
Starts a loop that runs as long as a condition remains true.
break
Exits the current loop immediately, skipping any remaining iterations.
continue
Skips the rest of the current loop iteration and moves to the next one.
pass
A no-operation placeholder. Used when a code block is syntactically required but intentionally left empty.
def
Defines a function. Everything indented below the def line becomes the function body.
class
Defines a class — a blueprint for creating objects with shared attributes and methods.
return
Exits a function and optionally sends a value back to the caller.
yield
Pauses a function and sends a value to the caller without exiting, turning the function into a generator.
lambda
Creates a small, anonymous (unnamed) function in a single expression.
del
Removes a variable, an item from a list, or an attribute from an object.
import
Loads a module so you can use its contents in your program.
from
Used with import to pull specific names out of a module rather than importing the whole thing.
as
Creates an alias for an imported module or for an exception variable in a with or except block.
try
Wraps code that might raise an exception so that errors can be caught and handled gracefully.
except
Catches exceptions raised within the try block and specifies how to respond.
raise
Manually triggers an exception, either a new one or one that was caught.
finally
A block that always runs after try and except, regardless of whether an exception occurred. Used for cleanup tasks.
assert
Tests a condition and raises an AssertionError if it is false. Commonly used during development to catch bugs early.
with
Manages resources using a context manager, ensuring that setup and teardown happen automatically (for example, closing a file).
True
The Boolean value representing truth (equivalent to the integer 1).
False
The Boolean value representing falsity (equivalent to the integer 0).
None
Represents the absence of a value. Functions that do not explicitly return something return None by default.
and
A logical operator that returns True only when both operands are truthy.
or
A logical operator that returns True when at least one operand is truthy.
not
A logical operator that inverts a Boolean value — True becomes False and vice versa.
in
A membership operator that checks whether a value exists inside a sequence or iterable. Also used as part of a for loop header.
is
An identity operator that tests whether two variables point to the exact same object in memory, not just equal values.
global
Declares that a variable inside a function refers to the one at module (global) scope rather than creating a local copy.
nonlocal
Declares that a variable inside a nested function refers to the enclosing (but not global) scope, allowing the nested function to modify it.
async
Declares a function as a coroutine — a function that can be paused and resumed, used with the asyncio library for concurrent programming.
await
Used inside an async function to pause execution until an awaitable object (such as another coroutine) completes.

The code below shows several categories in action in a single short program:

python
# import (imports), as (alias)
import math as m

# def (definition), return (definition)
def describe_number(n):
    if n > 0:           # if (control flow)
        return "positive"
    elif n < 0:         # elif (control flow)
        return "negative"
    else:               # else (control flow)
        return "zero"

# for (control flow), in (logical/membership)
for num in [3, -1, 0]:
    result = describe_number(num)
    if result is not None:   # is, not (logical)
        print(result)

# try / except / finally (exception handling)
try:
    value = m.sqrt(-1)
except ValueError as e:      # except, as
    print("Error:", e)
finally:
    print("Done")

Soft Keywords in Python

Python 3.10 introduced a new category called soft keywords. A soft keyword acts like a reserved keyword only in a specific syntactic position. Outside that position, it behaves as a regular identifier and can be used as a variable or function name without raising an error.

Python 3.13 has four soft keywords: match, case, type, and _. The first three were introduced for structural pattern matching (added in Python 3.10), and type was added in Python 3.12 for the type alias statement.

match
case
type
_
python
# 'match' and 'case' act as keywords here (Python 3.10+)
command = "quit"

match command:
    case "quit":
        print("Exiting.")
    case "help":
        print("Showing help.")
    case _:          # '_' is a wildcard soft keyword here
        print("Unknown command.")

# Outside the match block, 'match' is just an identifier
match = "a regular variable"
print(match)   # prints: a regular variable

# 'type' as a soft keyword (Python 3.12+)
type Point = tuple[int, int]   # defines a type alias
Caution

Even though soft keywords are technically valid as variable names, using them as identifiers in code that also uses pattern matching creates confusing programs. Treat them as reserved in practice, even when the language does not require it.

spot the bug click the line with the error

This code attempts to define a function and loop through a list. One line contains an error caused by using a Python keyword as a variable name. Click the line you think is wrong:

1 def calculate(numbers):
2 total = 0
3 for = len(numbers)
4 for n in numbers:
5 total += n
6 return total
The fix: Line 3 uses for as a variable name with for = len(numbers). Since for is a reserved keyword, Python raises a SyntaxError. The fix is to rename the variable to something like count = len(numbers).

How to Identify and Use Python Keywords Correctly

Knowing a keyword exists and using it correctly are two different things. These four steps will help you work with keywords confidently from the start.

  1. Check the keyword list for your Python version

    Open the Python REPL and run import keyword followed by print(keyword.kwlist). The output reflects exactly which words are reserved in the version you have installed. This is the authoritative source — always use it when in doubt rather than relying on memory.

  2. Use syntax highlighting as a visual guide

    Every modern code editor — VS Code, PyCharm, Sublime Text — highlights reserved keywords in a distinct color. When you type def or return, the editor changes their color automatically. If a word you intended as a variable name suddenly turns the keyword color, that is a clear signal to rename it.

  3. Avoid naming variables after keywords

    Before settling on a variable name, do a quick mental check against common keywords. Names like list, type, id, and input are not keywords, but they are built-in names — overriding them causes subtle bugs. Stick to descriptive names that describe the data they hold: user_input instead of input, item_list instead of list.

  4. Learn keywords by category, not as a list

    Memorizing 35 words in isolation is harder than learning seven or eight small groups. Start with the control flow keywords (if, elif, else, for, while, break, continue, pass) and the definition keywords (def, class, return). These appear in every program. Build from there into exception handling, imports, and scope.

Python Learning Summary Points

  1. Python 3.12 and 3.13 have 35 reserved keywords that cannot be used as variable names, function names, or any other identifiers. Attempting to do so raises a SyntaxError.
  2. All reserved keywords are lowercase except True, False, and None, which are capitalized. Case matters — while is a keyword, While is not.
  3. Python also has four soft keywords — match, case, type, and _ — that act as keywords only in specific syntactic contexts and can be used as identifiers elsewhere.
  4. You can inspect the current keyword list at any time with import keyword; print(keyword.kwlist), which reflects the exact list for your installed Python version.
  5. Learning keywords by category (control flow, definitions, imports, exception handling, logical operators, scope, async) is more effective than rote memorization of an unordered list.

Python keywords are not something to fear. As a beginner, you will start using if, for, def, and return within your first hour of writing Python. The other keywords become natural as you progress into more advanced topics. Understanding that these words are off-limits as identifiers — and knowing why — removes a whole category of beginner confusion before it has a chance to surface.

check your understanding question 1 of 5

Frequently Asked Questions

Python keywords are reserved words that are part of the language's syntax. They have fixed, predefined meanings and cannot be used as variable names, function names, or any other identifiers. As of Python 3.12, there are 35 reserved keywords.

Python 3.12 and 3.13 have 35 reserved keywords. In addition, there are 4 soft keywords — match, case, type, and _ — which act as keywords only in specific contexts and can be used as identifiers elsewhere.

No. Reserved keywords cannot be used as variable names, function names, class names, or any other identifiers. Doing so raises a SyntaxError. Soft keywords, however, can be used as identifiers outside of their specific contexts.

Yes. Python keywords are case-sensitive. With the exception of True, False, and None which are capitalized, all other reserved keywords are entirely lowercase. Writing IF or While instead of if or while makes them valid identifier names, not keywords.

You can view all current keywords by importing the keyword module and printing keyword.kwlist. Running help('keywords') in the Python REPL also displays the complete list for your installed Python version.

A reserved keyword is permanently set aside by the Python interpreter and can never be used as an identifier. A soft keyword only acts as a keyword in specific syntactic positions. For example, match and case function as keywords inside a match statement, but can be used as variable names elsewhere.

Python raises a SyntaxError when you attempt to assign a value to a reserved keyword or use one in a position that violates its intended syntax. For example, writing for = 5 produces SyntaxError: invalid syntax.

Beginners should focus on the control flow and definition keywords first: if, else, elif, for, while, def, return, import, and class. These appear in nearly every Python program and understanding them is essential before moving to more advanced keywords like async, await, yield, or nonlocal.

The pass keyword is a placeholder statement that does nothing. It is used when a block of code is syntactically required but you have no content to put there yet — such as an empty function body, an empty class definition, or an empty conditional branch.

Yes. In Python 2, print and exec were reserved keywords. Both were converted to built-in functions in Python 3 and removed from the keyword list. The async and await keywords were added in Python 3.7, and the type soft keyword was introduced in Python 3.12.