'''集合的生成式''' s='hello,hello' print(s.index('lo')) #3 print(s.find('lo')) #3 print(s.rindex('lo')) #9 print(s.rfind('lo')) #9 '''如果查找不存在的元素''' #print(s.index('k')) #ValueError: substring not found 抛异常 print(s.find('k')) #-1 不会抛异常返回值为-1 #print(s.rindex('k')) #ValueError: substring not found 抛异常 print(s.rfind('k')) #-1 不会抛异常返回值为-1
E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonProject/demon1/demo14.py
3
3
9
9
-1
-1