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

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

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