mishrajicoder

New Member
Joined
Oct 17, 2022
Messages
6
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.
 

Solution
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

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,998
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
 

AlishS

New Member
Joined
Oct 27, 2022
Messages
9
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
 

Solution