Python – Get the list of all keywords programmatically
To get the list of all keywords of Python programmatically, you can use kwlist of keyword library.
Following is the quick code snippet to get the list of all keywords.
import keyword
s = keyword.kwlist
kwlist
returns sequence containing all the keywords defined for the interpreter.
Example 1: Get all Python Keywords programmatically
In the following example, we will get all the Python keywords using kwlist property and print them using a for loop.
Python Program
import keyword
if __name__ == '__main__':
#get all keywords
keywords = keyword.kwlist
#print the keywords
for key in keywords:
print(key)
Run 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
This is the list of all keywords in Python.
Summary
In this tutorial of Python Examples, we learned how to get the list of all Python keywords programmatically.
Related Tutorials
- Python List without Last Element
- Python List of Functions
- How to Reverse Python List?
- Python – List of Strings
- Shuffle Python List
- How to Append List to Another List in Python? – list.extend(list)
- Python Program to Find Duplicate Items of a List
- Python – Count the items with a specific value in the List
- Python Program to Find Largest Number in a List
- How to Insert Item at Specific Index in Python List?