
find()方法返回子字符串首次出现的索引值(如果找到)。如果找不到,则返回-1。
find()方法的语法为:
str.find(sub[, start[, end]] )
find()参数
find()方法最多使用三个参数:
- sub- 它是在str字符串中要搜索的子字符串。 
- start和end (可选)-在其中搜索子字符串str[start:end] 
find()返回值
find()方法返回一个整数值。
- 如果字符串中存在子字符串,则返回该子字符串首次出现的索引。 
- 如果字符串中不存在子字符串,则返回-1。 

示例1:无开始和结束参数的find()
quote = 'Let it be, let it be, let it be'
result = quote.find('let it')
print("子字符串 'let it':", result)
result = quote.find('small')
print("子字符串 'small ':", result)
# 如何使用find()
if  (quote.find('be,') != -1):
  print("包含字符串 'be,'")
else:
  print("未包含字符串")运行该程序时,输出为:
子字符串 'let it': 11 子字符串 'small ': -1 包含字符串 'be,'
示例2:带有开始和结束参数的find()
quote = 'Do small things with great love'
# 搜索子字符串 'hings with great love'
print(quote.find('small things', 10))
# 搜索子字符串 ' small things with great love' 
print(quote.find('small things', 2))
# 搜索子字符串 'hings with great lov'
print(quote.find('o small ', 10, -1))
# 搜索子字符串 'll things with'
print(quote.find('things ', 6, 20))运行该程序时,输出为:
-1 3 -1 9
