Python String find() Method
The find() method is a string method that returns the lowest index of a substring within a string if it is found. If not, it returns -1.
For example:
s = "Hello world"
print(s.find("world")) # prints 6
print(s.find("Python")) # prints -1
You can also specify the start and end positions to search within a slice of the string.
For example:
s = "Hello world"
print(s.find("o", 5)) # prints 7
print(s.find("o", 5, 8)) # prints -1
If you have any questions about this code, you can drop a line in comment.
Comments
Post a Comment