• notice
  • Congratulations on the launch of the Sought Tech site

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


Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+