Python Keywords
Syntax Satellite
Python Keywords
Keywords are reserved by the language. Know them so you don't accidentally reuse them or misunderstand their semantics.
Keyword table
| Keyword | Purpose |
|---|---|
| and / or / not | Logical operators |
| if / elif / else | Conditionals |
| for / while / break / continue | Loops |
| match / case | Pattern matching |
| def / return / yield / lambda | Functions & generators |
| class | Define classes |
| try / except / finally / raise | Error handling |
| with | Context managers |
| import / from / as | Module management |
| global / nonlocal | Scope controls |
| pass | Empty placeholder |
| True / False / None | Singleton constants |
See keyword.kwlist for the authoritative set at runtime.
Examples
import keyword
print(keyword.kwlist)
Avoid using keywords as variable names. IDEs usually highlight them in distinct colors.