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
Post a Comment