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 Overflow
🌐
W3Schools
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....
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.6 documentation
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. For example: >>> 'spam, spam, spam'.find('sp') 0 >>> 'spam, spam, spam'.find('sp', 5) 6
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-find
Python String find() Method - GeeksforGeeks
April 26, 2025 - find() method in Python returns the index of the first occurrence of a substring within a given string. If the substring is not found, it returns -1. This method is case-sensitive, which means "abc" is treated differently from "ABC".
Find elsewhere
🌐
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().
🌐
Analytics Vidhya
analyticsvidhya.com › home › a comprehensive guide to python string find() method
A Comprehensive Guide To Python String find() Method - Analytics Vidhya
May 19, 2025 - The Python String find() method is a powerful tool for searching for a specific substring within a given string. This method returns the index of the first occurrence of the substring, or -1 if the substring is not found.
🌐
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.
🌐
Learn By Example
learnbyexample.org › python-string-find-method
Python String find() Method - Learn By Example
April 20, 2020 - Python · Searches the string for a given substring · The find() method searches for the first occurrence of the specified substring sub and returns its index. If specified substring is not found, it returns -1. The optional arguments start ...
🌐
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?