Python-find

s = 'Hi buddy, if you have something to say, than say; if you have nothing to say, than go!'

# 子串查找,找到返回首次出现的位置(下标),找不到返回-1
# ret = s.find('good')
# 从后面开始查找
# ret = s.rfind('if')
# 统计次数
# ret = s.count('if')

# 判断是否以指定内容开头
# ret = s.startswith('Hi')

# 判断是否以指定内容结束
ret = s.endswith('go')

print(ret)

猜你喜欢

转载自blog.csdn.net/huaxiawudi/article/details/81165507
今日推荐