python字符串的查找

python字符串的查找:

mystr = "hello world and itcast and itheima and Python"

# 1. find()
# print(mystr.find('and'))  # 12
# print(mystr.find('and', 15, 30))  # 23
# print(mystr.find('ands'))  # -1 , ands子串不存在

python字符串的查找:
# 2.index()
# print(mystr.index('and'))  # 12
# print(mystr.index('and', 15, 30))  # 23
# print(mystr.index('ands'))  # 如果index查找子串不存在,报错

# 3.count()
# print(mystr.count('and', 15, 30))
# print(mystr.count('and'))  # 3
# print(mystr.count('ands'))  # 0

# 4.rfind()
# print(mystr.rfind('and'))  #最后一个and的首位置
# print(mystr.rfind('ands'))

# 5.rindex()
# print(mystr.rindex('and'))   #最后一个and的首位置
# print(mystr.rindex('ands'))

你可能感兴趣的:(tensorflow,opencv,python,开发语言,后端)