It is usual to check for an item in a list, tuple, or dict using 'in' operator.
List=[ 'l' , 'i' , 's' , 't']
if 's' in List:
print "success"
for string we usually go with 'find' function. Its quite easier to go with 'in' operator for string too.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
str1 = "this is string example"; | |
str2 = "is"; | |
if str1.find(str2) != -1: | |
print "found" | |
#Its quite easier to go with 'in' operator for string too. | |
if str2 in str1: | |
print "found" |
0 comments:
Post a Comment