How to get all the Keywords in Python?
Last updated: Mon. Sep. 14, 2026
When naming variables in Python, you are not allowed to use keywords as variable names. This means that you should familiarise yourself with the Python keywords.
Python generously provides a module that helps with this called the keyword module. All you have to do is import the module and get the list of keywords by accessing the kwlist attribute of the module.
First open your Command Line or Terminal and enter python. This will launch the python interpreter. Next you import the keyword module, loop through its kwlist attribute and output each keyword on a separate line:
```python
import keyword
for i,k in enumerate(keyword.kwlist, 1):
print(i, k)
```
Output:
1 False
2 None
3 True
4 and
5 as
6 assert
7 async
8 await
9 break
10 class
11 continue
12 def
13 del
14 elif
15 else
16 except
17 finally
18 for
19 from
20 global
21 if
22 import
23 in
24 is
25 lambda
26 nonlocal
27 not
28 or
29 pass
30 raise
31 return
32 try
33 while
34 with
35 yield
Now you know there are 35 keywords in Python. You also now know what names to avoid when naming your objects in Python.
Happy coding!