Python-find
程序员文章站
2022-07-12 14:34:29
...
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)
推荐阅读