Android Python string find() examples

mishrajicoder

New Member
Joined
Oct 17, 2022
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.
Python:
>>> x = "Hello World"
>>> x.find('World')
6
>>> x.find('Aloha');
-1
Could you please help me? But I'm not convinced.
 
If a match isn't found it will return -1. If found it returns the starting index. Indexes start at 0 which is the beginning of the string
 
1. Find a substring in a string:
>>> s = "this is a string"
>>> s.find("is")
2

2. Find a substring in a string, starting at a given index:
>>> s.find("is", 3)
-1

3. Find a substring in a string, using a given start and end index:
>>> s.find("is", 3, 6)
-1
 
Back
Top Bottom