Examples for string find in Python

0 votes

I am trying to find some examples but no luck. Does anyone know of some examples on the net? I would like to know what it returns when it can't find, and how to specify from start to end, which I guess is going to be 0, -1.

Aug 29, 2018 in Python by bug_seeker
• 15,350 points
33 views

1 answer to this question.

0 votes

you can use str.index too:

>>> 'sdfasdf'.index('cc') 
Traceback (most recent call last):
File "<pyshell#144>", line 1, in <module>
'sdfasdf'.index('cc') 
ValueError: substring not found 
>>> 'sdfasdf'.index('df') 
1
answered Aug 29, 2018 by Priyaj
• 56,520 points

Related Questions In Python

0 votes
1 answer

Slice notation in Python for string reversal

The slice notation is [start:end:step]. Step = ...READ MORE

answered Apr 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
85 views
0 votes
1 answer

In python how to test a string for a substring

if "ABCD" in "xxxxABCDyyyy": This can be used ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 56,520 points
64 views
0 votes
1 answer
0 votes
1 answer

How to search for a word in a string in Python?

You can do it like this: txt = ...READ MORE

answered Apr 4 in Python by Kumar
27 views
0 votes
2 answers

How do I find all files containing specific text on Linux?

grep -rnw 'text to find recursively inside ...READ MORE

answered May 20 in Linux Administration by Ritesh Singh
4,493 views
0 votes
1 answer

How to create new folder?

You can create a folder with os.makedirs() and use os.path.exists() to ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,520 points
122 views
0 votes
1 answer
0 votes
1 answer

Python constructors and __init__

There is no function overloading in Python, ...READ MORE

answered Oct 11, 2018 in Python by SDeb
• 13,160 points
105 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29 in Python by rajesh
• 1,210 points
81 views
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

answered Sep 3, 2018 in Python by Parul Raheja
474 views