返回顶部

收藏

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

标签:Python,String

收藏

0人收藏

支持

0

反对

0

发表评论