Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Print Python keywords using the keyword module - Python Program

To print a list of all Python keywords using the keyword module, follow these steps:

  • Import the keyword module: This module provides access to Python's keyword list.

                       import keyword

  • Access the kwlist attribute: The kwlist attribute within the keyword module is a list containing all the current Python keywords.

                     print(keyword.kwlist)

# Imports the keyword module and prints all Python keywords import keyword print("Python keywords:") print(keyword.kwlist)

Output

 
OUTPUT  :

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

Uses the built-in keyword module to display all reserved keywords in Python.