Keywords are special words which comes built in a programming language. They are used to perform basic operations which the programmer will need frequently such as looping, or for performing special and  important actions in the language. Together with identifiers, constants  and language symbols , keywords  forms the building blocks of statements in a language.

Python like many other languages comes with it's inbuilt set of keywords. we can use these keywords directly without any special actions like importing them. It is worth noting that Keywords in Python are different from builtin functions, for example  print() is not a keyword it is a builtin function.

The types in Python  are also  not categorized as keywords, they may share much in common like coming inbuilt into the language, but keywords have some special features which sets them apart. For example it is illegal to assign keywords to  variables or pass them to functions and doing this will raise a SyntaxError, but it is perfectly legal with types  though it is still not a very good idea. The reason why you cannot assign keywords to variables or pass them to functions is because they have no value, they are simply tools to aid in program development. Types  on the other hand, are literally Python classes and they, therefore, have value.

Keywords available in Python

As of now, Python keywords totals to 35 even though more keywords might be added and some removed in future versions of Python. For example the async and the await keywords are relatively new and they didn't exist  until Python 3.7 also  print and exec are  keywords in Python 2 but were removed from keywords in python 3. 

The 35  keywords available in the current versions of Python  as of now are:

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

IDEs/Editors usually highlights keywords differently.This can help a programmer to  identify them easily and avoid using them incorrectly.

You can use the builtin help() function to get more details about  the keywords, for example to view all the keywords available in your version of Python you can pass "keywords" as the argument to the help() function as shown below.

passing "keywords" to Pythons help function 

You can also pass the   name of a specific keyword to get more information about it. For example:

Using python help function with "lambda" as the arguments

 
The keyword module

The Python standard library also comes with a builtin  module called keyword ,  you can use this module  to work with the keywords programmatically. This module provides four utilities to work with keywords, these are

  1. kwlist
  2. iskeyword()
  3. softkwlist
  4. issoftkeyword()

The kwlist  as the name tries to suggest is  a list containing all the keywords present in the Python version.

import keyword
print(keyword.kwlist)#prints a list containing all the keywords available
print(len(keyword.kwlist))# prints the number of keywords

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

35

To check whether a given word is a keyword , you can use the iskeyword() function in the module like:

import keyword
print(keyword.iskeyword("pass"))
print(keyword.iskeyword("str"))

True

False

Soft keywords.

From Python 3.10 onwards, two keywords were introduced, match and case . These keywords are not yet supported as full keywords and the language refers to them as soft  Keywords. They can be used as normal words , like being  assigned to variables or as any valid identifier. 

The softkwlist  in the keyword module is a list containing the soft keywords while the issoftkyword() function can be used to check whether a given word is a soft keyword.

import keyword
print(keyword.softkwlist)
//['_', 'case', 'match']
print(keyword.issoftkeyword("match"))
//True

You can check on  Python's Implementation of Switch-Case , to see a detailed exploration of match and case keywords in python.

Categorizing Python keywords

We can group the 35 keywords according to their purpose  and usage as follows:

 

Value Keywords
True False  None 
Operator Keywords
and or not  in is  
Control Flow Keywords
if elif else
Iteration Keywords
for while break continue else
Structure Keywords
def class with as pass lambda
Returning Keywords
return  yield
Import Keywords
import from as
Exception-Handling Keywords
try except raise finally else assert
Asynchronous Keywords
async await
Variable Handling Keywords
del global nonlocal