keyword.iskeyword()
The is keyword.iskeyword() command is used with the keyword module to check if a word is a keyword within the Python Programming Language. We must import the module for this command to work . If a word is a keyword we will get a boolean as True and if a word is not a keyword in Python then we will get a boolean False.
keyword.iskeyword() Syntax
keyword.iskeyword(‘word’)
Note that the word needs to be in a string format.
keyword.iskeyword() Example
#keyword.iskeyword() Example
#import keyword module
>>> import keyword
#check if a word is a keyword with a True return
>>> keyword.iskeyword('def')
True
#check if a word is a keyword with a False return
>>> keyword.iskeyword('dog')
False
#remove keyword module
>>> del keyword
keyword.iskeyword()
No comments:
Post a Comment