Python string find() examples

I’m looking for examples, but I’m not finding any.
Are there any examples on the internet? I’d like to know what it returns when it can’t find something, as well as how to specify the starting and ending points, which I assume will be 0, -1.

>>> x = "Hello World"
>>> x.find('World')
6
>>> x.find('Aloha');
-1

Could you please help me? But I’m not convinced.

From the Python documentation: If you look for substring sub in a string:

Return -1 if sub is not found.

This can be found at:
https://docs.python.org/3/library/stdtypes.html#str.find

That also specifies how to use the start and stop parameters to limit your search.

The documentation is generally very good and will answer most if not all of this type of queries.

3 Likes