Python Keywords

In this article, you will learn about python keywords. These are the pre-defined reserve words in python. Each keyword has its own specific identity and assigned task.  

In python, these keywords cannot be used as variable names, function names, and other identifiers. If we use them as variables the python interpreter treats them as keywords. There are almost 35 keywords in python. They may vary depending on which python version you are using.

How to check keywords in python

You can use the help () function to check the list of keywords in your current version of python.

help()
help> keywords

Output

Here is a list of the Python keywords.  Enter any keyword to get more help.

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

Program to check keywords in python

Here is the python code to check the list of python keywords.

import keyword
print(keyword.kwlist)

Output

['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']