I'm not sure what you're looking for, do you mean find()?
>>> x = "Hello World"
>>> x.find('World')
6
>>> x.find('Aloha');
-1
Answer from Paolo Bergantino on Stack OverflowW3Schools
w3schools.com › python › ref_string_find.asp
Python String find() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Bootcamp Python Training ... The find() method finds the first occurrence of the specified value....
Mimo
mimo.org › glossary › python › string-find
Python string.find(): Syntax, Usage, and Examples
The method specifically returns ... methods in languages like Java or JavaScript. The .find() method is a built-in string method used to locate the starting index of the first occurrence of a substring within another string....
Videos
Python String find - YouTube
10:31
Python String Find Method: Beginners Example Code 2024 - YouTube
How to Find in String using Python | String Contains Substring ...
17:38
Identifying a Substring Within a Python String - YouTube
15:15
How To Check A String For A Character In Python - YouTube
05:27
Python Find String Method - YouTube
Reddit
reddit.com › r/learnpython › python string find() examples
r/learnpython on Reddit: Python string find() examples
October 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.
>>> x = "Hello World"
>>> x.find('World')
6
>>> x.find('Aloha');
-1Could you please help me? But I'm not convinced.
Top answer 1 of 5
24
https://docs.python.org/3/library/stdtypes.html?highlight=str%20find#str.find https://www.w3schools.com/python/ref_string_find.asp
2 of 5
23
u/Shiba_Take has linked to the official docs, which is the go-to source for anything you need to know about Python. You should try to familiarize yourself with the site, and the notation it uses, as it should answer the very questions you were asking. str.find(sub[, start[, end]]) Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found. Note that the square brackets indicate an optional argument, so you could include starting and ending indices, if you wish.
Top answer 1 of 9
114
I'm not sure what you're looking for, do you mean find()?
>>> x = "Hello World"
>>> x.find('World')
6
>>> x.find('Aloha');
-1
2 of 9
45
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
Programiz
programiz.com › python-programming › methods › string › find
Python String find()
The find() method returns the index of first occurrence of the substring (if found). If not found, it returns -1. ... If the substring exists inside the string, it returns the index of the first occurence of the substring. If a substring doesn't exist inside the string, it returns -1. Working ...
DataCamp
datacamp.com › tutorial › python-string-contains
Python String Search and Replace: in, .find(), .index(), . ...
March 31, 2026 - Practical patterns for finding, counting, and replacing substrings in modern Python. ... It’s common to reach for .find() or .index() to check if text exists in a string—and then run into odd behavior like a ValueError or a missed match at the start of the string.
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Python string find() examples - Raspberry Pi Forums
needle=" " haystack="Hello World" haystack[haystack.find(needle)+len(needle):] == 'World' haystack[:haystack.find(needle)] == 'Hello' also note haystack.endswith(needle) and haystack.startswith(needle) these return True/False depending on if it is found at the start/end of the string · My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT ... Not convinced of what? Anyway start python and type some thing in, see what it gives you and returns A place to start, since you can also hit the try button, is https://www.w3schools.com/python/ref_string_find.asp
CodeSignal
codesignal.com › learn › courses › practicing-string-operations-and-type-conversions-in-python › lessons › exploring-substring-search-in-python-strings
Exploring Substring Search in Python Strings
We use the built-in zip() function to create pairs of original strings and substrings. We then use the find() method to find the first occurrence of each substring in its related original string. Python string objects have a built-in method called str.find(substring, starting_index=0), which ...
Stanford CS
cs.stanford.edu › people › nick › py › python-string.html
Python Strings
Similarly, if the start index is greater or equal to the end index, the slice is just the empty string. >>> s = 'Python' >>> s[2:999] 'thon' >>> s[3:2] # zero chars ''
Codecademy
codecademy.com › article › how-to-check-if-a-string-contains-a-substring-in-python
How to Check if a String Contains a Substring in Python | Codecademy
The .find() method in Python is another built-in method that we can use to locate substrings within a string. This method checks the main string and returns the index of the first occurrence of the given substring, just like .index().
Hyperskill
hyperskill.org › university › python › find-method-in-python
Python find() Method
December 25, 2025 - The Python find() method is used to search for a specified substring within a string and return the index of its first occurrence.
Codecademy
codecademy.com › docs › python › strings › .find()
Python | Strings | .find() | Codecademy
July 26, 2025 - Python’s .find() method is a built-in string method that searches for a specified substring within a string and returns the index of the first occurrence.
Real Python
realpython.com › python-string-contains-substring
How to Check if a Python String Contains a Substring – Real Python
December 1, 2024 - The in membership operator is the recommended way to check if a Python string contains a substring. Converting input text to lowercase generalizes substring checks by removing case sensitivity. The .count() method counts occurrences of a substring, while .index() finds the first occurrence’s ...
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
June 16, 2026 - Every example runs in a standard Python 3.6+ environment (tested on the latest stable release, Python 3.14) and uses only the standard library, with no extra packages. ... Use the in operator ("target" in my_list) for a fast, easy-to-read check; it returns True or False. On a list, in checks for an exact match, not a partial one. So "app" in ["apple"] is False. Use list.index("target") to get the position of the first match. Wrap it in a try/except ValueError block, since it raises an error when the string is not there. To find all matching positions, use a list comprehension with enumerate(): [i for i, val in enumerate(my_list) if val == "target"].
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
May 25, 2026 - Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding Match. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.
Spiceworks
community.spiceworks.com › programming & development
Python string find examples - Programming & Development - Spiceworks Community
October 17, 2022 - I’m looking for examples, but I’m not finding any. I am really tired of searching about what is really abstract data type in python. I tried reading this , but I’m not able to understand it correclty. 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. Could you please help me?