Showing results for python find in string
Search instead for python rfind in string

There is no simple built-in string function that does what you're looking for, but you could use the more powerful regular expressions:

import re
[m.start() for m in re.finditer('test', 'test test test test')]
#[0, 5, 10, 15]

If you want to find overlapping matches, lookahead will do that:

[m.start() for m in re.finditer('(?=tt)', 'ttt')]
#[0, 1]

If you want a reverse find-all without overlaps, you can combine positive and negative lookahead into an expression like this:

search = 'tt'
[m.start() for m in re.finditer('(?=%s)(?!.{1,%d}%s)' % (search, len(search)-1, search), 'ttt')]
#[1]

re.finditer returns a generator, so you could change the [] in the above to () to get a generator instead of a list which will be more efficient if you're only iterating through the results once.

Answer from moinudin on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_string_find.asp
Python String find() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A 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....
Discussions

python - How to find all occurrences of a substring? - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. Python has string.find() ... More on stackoverflow.com
🌐 stackoverflow.com
Examples for string find in Python - Stack Overflow
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 g... More on stackoverflow.com
🌐 stackoverflow.com
Python string find examples
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 ... More on community.spiceworks.com
🌐 community.spiceworks.com
3
6
October 17, 2022
if in vs. str.rfind()
First of all, those aren't strings; they're tuples. Tuples have no rfind() method, so your friend's code is broken and will not run (try it!). For the sake of illustration, let's replace that problem with one that actually does involve strings: if 'spoon' in 'my spoon is too spoony': print True This will search for the substring "spoon", and print True. If you just want to see if 'spoon' is in the larger string, this is the most straightforward and Right way to do it. Now let's look at what find() and rfind() would do: 'my spoon is too spoony'.find('spoon') # returns 3 'my spoon is too spoony'.rfind('spoon') # returns 16 These look for a substring, starting at the beginning or end of the larger string, respectively. Use one of them if you need to know the location of the substring. In general: if there are two equivalent ways of doing something, and one of them is simpler and more readable, that's the one to go with. More on reddit.com
🌐 r/Python
26
8
February 26, 2012
🌐
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');
-1

Could you please help me? But I'm not convinced.

the .find method Oct 29, 2022
r/learnpython
3y ago
search in string (python) Dec 11, 2022
r/learnprogramming
3y ago
Find a string in a list of lists... Apr 18, 2022
r/learnpython
4y ago
More results from reddit.com
🌐
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".
🌐
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.
🌐
Python Basics
pythonbasics.org › home › python basics › string find() in python
String find() in Python - pythonbasics.org
The find(query) method is built-in to standard python. Just call the method on the string object to search for a string, like so: obj.find("search"). The find(
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
Learn how to find a string in a Python list using in, index(), list comprehension, and regex. See practical, runnable code examples and start today.
🌐
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
In original.find(substring), we pass the 'substring' that we want to locate. The function begins the search from the beginning as we have not specified a starting position. Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignalStart learning today! [ "The substring 'loW' was found in the original string 'HelloWorld' at position(s) 3.", "The substring 'ear' was found in the original string 'LearningPython' at position(s) 1.", "The substring 'o' was found in the original string 'GoForBroke' at position(s) 1, 3, 7.", "The substring 'Ba' was found in the original string 'BackToBasics' at position(s) 0, 6." ]
🌐
Programiz
programiz.com › python-programming › methods › string › find
Python String find()
Online Python Online JavaScript ... 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....
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
The result depends on the number of capturing groups in the pattern. If there are no groups, return a list of strings matching the whole pattern. If there is exactly one group, return a list of strings matching that group. If multiple groups are present, return a list of tuples of strings matching the groups. Non-capturing groups do not affect the form of the result. >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10') [('width', '20'), ('height', '10')]
🌐
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 › 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.
🌐
W3Schools
w3schools.com › python › python_strings.asp
Python Strings
Strings in python are surrounded by either single quotation marks, or double quotation marks.
🌐
GitHub
github.com › sharkdp › fd
GitHub - sharkdp/fd: A simple, fast and user-friendly alternative to 'find' · GitHub
August 9, 2026 - fd is designed to find entries in your filesystem. The most basic search you can perform is to run fd with a single argument: the search pattern. For example, assume that you want to find an old script of yours (the name included netflix): > ...
Author: sharkdp
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
This method is string-based; it neither accesses the filesystem nor treats “..” segments specially. The following code is equivalent: >>> u = PurePath('/usr') >>> u == p or u in p.parents False
🌐
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.
🌐
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?
🌐
Hyperskill
hyperskill.org › university › python › find-method-in-python
Python str.find() — Find a Substring & Handle -1 Return
August 10, 2026 - ... This course is dedicated to ... be it Backend Development or Data Science. ... The Python find() method is used to search for a specified substring within a string and return the index of its first occurrence....