jinian1002
# python中index()和find()函数的区别:
"""
1、二者都可以返回需要查询的字符串在源字符串中的初识索引位置
2、当所查询的字符串不存在的时候,index()会抛出异常,find()会返回一个-1
"""
a = "c++|c#|java|python|js|php"

# 下边两个都会返回12,即python中的p在字符串a中的索引位置
res = a.index(\'python\')
# res = a.find(\'python\')

# res = a.index(\'pythson\')  # 会抛出异常
# res = a.find(\'pythson\')  # 会返回-1
print(res)

 

分类:

技术点:

相关文章:

  • 2021-10-17
  • 2022-02-23
  • 2021-12-05
  • 2022-12-23
  • 2021-12-06
  • 2021-09-04
  • 2022-03-04
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2021-09-13
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案