Signup/Sign In
LAST UPDATED: DECEMBER 16, 2019

Getting the list of Keywords in Python

    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.

    I am a Computer Science Student. I am interested in Programming. I love to know about new technologies.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS