Display the keywords and the number of keywords in Python

Kalpana P
1 min readMar 17, 2024

--

Keywords: They are the predefined reserved words in Python that have special meanings and purposes and cannot be used as identifiers/variables, functions, classes, modules, etc.,

The predefined variable kwlist of the keyword module helps identify the keywords in Python.

Coding

>>>import keyword #import the keyword module

>>>keyword.kwlist #displays a list comprising of the keywords in Python

[‘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’]

(OR)

#help function without any argument starts an interactive help utility on the console

>>>help()

help> #prompt of interactive help utility.

#type keywords in the help utility to see the Python keywords

help>keywords

List of Python Keywords

#print the number of keywords in Python

>>>no_of_keywords=len(keyword.kwlist)

>>>print(“Number of keywords=”,no_of_keywords)

Number of keywords=35

#Follow for Python Tips

--

--

Kalpana P

Working as an Assistant Professor in the Department of Computer Science, CHRIST(Deemed to be University), Bangalore.