+3 votes
in Programming Languages by (63.5k points)
I want to know the list of keywords in Python to make sure that my variable names are different from keywords.

Is there any way to find all Python keywords?

1 Answer

0 votes
by (271k points)

There is a Python module called "keyword". You can use it to determine all the keywords defined for the interpreter.

Here is the code for that using Python 3.8.2:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']