Python Keywords An Introduction

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> keywords


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


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