Finding a substring in a string
string2 = "Odd or even"
# find index of "even"
try:
print '"even" index is', string2.index( "even" )
except ValueError:
print '"even" does not occur in "%s"' % string2
if string2.startswith( "Odd" ):
print '"%s" starts with "Odd"' % string2
if string2.endswith( "even" ):
print '"%s" ends with "even"\n' % string2
Related examples in the same category