About Lesson
find:-
The find() method finds the first occurrence of the specified value. The find() method returns -1 if the value is not found. The find() method is almost the same as the index() method, the only difference is that the index() method raises an exception if the value is not found. (See example below)
Syntax:- string.find(value, start, end)
txt = “Hello, welcome to my world.” x = txt.find(“e”) print(x) # 1 |
txt = “Hello, welcome to my world.” x = txt.find(“e”, 5, 10) print(x) # 8 |
txt = “Hello, welcome to my world.” print(txt.find(“q”)) # -1 print(txt.index(“q”)) # valueError |