# 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)