Keywords are reserved words that Python uses for syntax.
You cannot use a keyword as a variable, function, class, or module name.
The easiest way to learn keywords is by job: control flow, functions, classes, imports, exceptions, async code, and boolean/null values.
Control keywords decide which block runs, how loops continue, and when a function returns.
| Keyword | Job |
|---|---|
| if / elif / else | Choose between branches |
| for / while | Repeat work |
| break / continue | Control loop flow |
| return | Send a value back from a function |
score = 82
if score >= 50:
print("pass")
else:
print("try again")
pass
if and else are keywords because they define Python syntax.
Definition keywords create reusable names for functions, classes, imports, and exception handling.
| Keyword | Job |
|---|---|
| def | Create a function |
| class | Create a class |
| import / from / as | Bring code into the current file |
| try / except / finally / raise | Handle or signal errors |
import keyword
print(keyword.iskeyword("class"))
print(keyword.iskeyword("course"))
True
False
The keyword module can check whether a word is reserved.
Reserved keywords are part of Python grammar and cannot be used as ordinary variable, function, class, or attribute names. Learn them by job instead of as an alphabetical wall; the grouping makes syntax easier to recall and reveals which words belong together.
Soft keywords act as grammar words only in specific contexts, so they may still be valid identifiers elsewhere. Current Python versions use match, case, and _ in structural pattern matching, and type in a type-alias statement. Check the documentation for the Python version your project supports because this list can evolve.
The standard keyword module reports the interpreter's actual reserved and soft-keyword sets. Use it in code generators, schema-to-Python tools, and linters before creating identifiers. Appending an underscore, such as class_, is the conventional repair for a generated name that collides with a keyword.
import keyword
print(keyword.iskeyword("class")) # True
print(keyword.issoftkeyword("match")) # True
print(keyword.kwlist)
print(keyword.softkwlist)
The module reflects the exact interpreter running the program, which is safer than copying a list from another Python release.
Try this next
0 of 3 completed
No. They are built-in functions. Keywords are reserved syntax words such as if, for, def, class, and return.
Yes, language versions can add syntax over time. Use the keyword module to check the interpreter you are using.
Python tries to read it as syntax, not as your custom variable name.
Explore 500+ free tutorials across 20+ languages and frameworks.