How to check if a given word is a Python keyword?
In this program, we will check if the given word is a python keyword. For this, we will use the iskeyword() function from the keyword library.
algorithm
Step 1: Import keyboard.Step 2: Check if the given string is a keyword or not.
sample code
import keywordwords = [ "city" , "music" , "in" , "if" ] for word in words: if keyword.iskeyword(word): print ( "{} is a keyword" .format(word)) else : print ( "{} is not a keyword" .format(word))
output result
city is not a keywordmusic is not a keyword in is a keyword if is a keyword
0 Comments