keyword
The keyword module tests whether a string is a Python keyword. Note that the keyword-checking mechanism is not tied to the specific version of Python being used.
keyword.kwlist
This is a list of all Python keywords.
>>> import keyword
>>> keyword.kwlist
['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise',
'return', 'try', 'while']
keyword.iskeyword()
This function tests whether a string is a Python keyword:
>>> import keyword
>>> str = "import"
>>> keyword.iskeyword(str)
1