Python Keyword Module
The keyword module gives us the ability to list out Python keywords or check if a word is a Python Keyword.
Step 1 – Import Keyword Module
#import keyword module
>>> import keyword
>>>
Step 2 – List out Python Keywords
#List Out Python Keywords
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', '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']
Step 3 – Is Keyword?
#Is Keyword?
>>> keyword.iskeyword('not')
True
>>> keyword.iskeyword('dog')
False
Step 4 – Remove Keyword Module
#Remove Keyword Module
>>> del keyword
If you have any questions about the Python Keyword Module leave a comment below.
Keyword Module
No comments:
Post a Comment