Skip to main content

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​

A selection of the most common keywords (Python 3.12)
KeywordPurpose
and / or / notLogical operators
if / elif / elseConditionals
for / while / break / continueLoops
match / casePattern matching
def / return / yield / lambdaFunctions & generators
classDefine classes
try / except / finally / raiseError handling
withContext managers
import / from / asModule management
global / nonlocalScope controls
is / inIdentity and membership tests
delDelete names and items
assertDebug-time invariant checks
async / awaitAsynchronous functions
passEmpty placeholder
True / False / NoneSingleton 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.

Next up in your learning path