Technology3 min read

Getting the list of Keywords in Python

Abhishek Ahlawat

By Abhishek Ahlawat โ€” Recently

Founder of StudyTonight and a MERN fullstack developer. Writes about JavaScript, web development, Linux, and tech.

#Python#Python Keyword

Summarize this article using AI

In this tutorial, we are going to learn how to get all the keywords that are present in Python. It's straightforward. We have a module called the keyword module, which contains a list of keywords in the kwlist variable. Hence to get a list of keywords in python we can use the following variable.




Steps to get the List of Keywords

  1. Import the keyword module.

  2. Print the variable keyword.kwlist to get a list of keywords.

Let's see the code.

Here's the code:

# importing the keyword module
import keyword

# getting the list of keywords
print(keyword.kwlist)

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



Conclusion

If you got any doubts while following the tutorial, mention them in the comment section.

Spotted something outdated or wrong?

Liked this? See more StudyTonight posts in Google results.

Add StudyTonight as a preferred source
Next questLIVE OPSStep 2 / 3

Practice real incidents in the browser

System Design Ops โ€” put out fires, ship fixes, and stack XP. Reading done. Time to play.

Play System Design
  • +XP

    Every sim

  • Incidents

    Live ops

  • Ranks

    Climb up

Read next