Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,038 questions

40,803 answers

573 users

How to check if any word in a string is reserved keyword in Python

1 Answer

0 votes
import keyword

keyword_list  = keyword.kwlist

string = 'python is True and return as global of all lists'

string_list = string.split()

for word in string_list:
   print(word,': ', word in keyword_list )

   
   
   
'''
run:
   
python :  False
is :  True
True :  True
and :  True
return :  True
as :  True
global :  True
of :  False
all :  False
lists :  False
 
'''

 





answered Jul 25, 2022 by avibootz

Related questions

1 answer 33 views
1 answer 74 views
1 answer 47 views
3 answers 136 views
...