Python string find() examples

Joined
Jun 29, 2022
Messages
28
Reaction score
0
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.
 
Joined
Nov 4, 2022
Messages
4
Reaction score
2
The 'find()' returns '-1' where the substring is not found as seen in your example with 'Aloha'.

The 'World' substring returns '6' as that is its index within X i.e.
0=H, 1=e, 2=l, 3:l, 4' ', 5:' ', 6:'World'
 
Joined
Jun 29, 2022
Messages
28
Reaction score
0
The 'find()' returns '-1' where the substring is not found as seen in your example with 'Aloha'.

The 'World' substring returns '6' as that is its index within X i.e.
0=H, 1=e, 2=l, 3:l, 4' ', 5:' ', 6:'World'
Thanks for the clarification, it really helped me a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top