strig=“what is your name”

substring="name"

str.endswith(suffix[, start[, end]])

str.find(sub[, start[, end]])

str.index(sub[, start[, end]])

str.rfind(sub[, start[, end]])

str.rindex(sub[, start[, end]])

str.startswith(prefix[, start[, end]])

in操作

>>> my_string="what is your name"
>>> substring="name"
>>> substring in my_string
True
>>> my_string.find(substring)
13
>>> my_string.rfind(substring)
13
>>> my_string.index(substring)
13
>>> my_string.endwith(substring)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'endwith'
>>> my_string.endswith(substring)
True

 

 

posted on 2016-01-02 10:00  保质期两天  阅读(355)  评论(0编辑  收藏  举报