Python: Find a word within a string -


i'm trying find word within string python.

str1 = 'this string' if 'is' in str1:     print str1 

in above example want not print str1. while in following example want print str2.

str2 = 'this string' if 'is' in str2:     print str2 

how go doing in python?

split string words , search them:

if 'is' in str1.split(): # 'is' in ['this', 'string']     print(str1) # never printed  if 'is' in str2.split(): # 'is' in ['this', 'is', 'a', 'string']     print(str2) # printed 

Comments

Popular posts from this blog

C# random value from dictionary and tuple -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -