keyword — Testing for Python keywords

Source code:Lib/keyword.py


This module allows a Python program to determine if a string is akeyword orsoft keyword.

keyword.iskeyword(s)

ReturnTrue ifs is a Pythonkeyword.

keyword.kwlist

Sequence containing all thekeywords defined for theinterpreter. If any keywords are defined to only be active when particular__future__ statements are in effect, these will be included as well.

keyword.issoftkeyword(s)

ReturnTrue ifs is a Pythonsoft keyword.

Added in version 3.9.

keyword.softkwlist

Sequence containing all thesoft keywords defined for theinterpreter. If any soft keywords are defined to only be active when particular__future__ statements are in effect, these will be included as well.

Added in version 3.9.