This is because str.index(ch) will return the index where ch occurs the first time. Try:

def find(s, ch):
    return [i for i, ltr in enumerate(s) if ltr == ch]

This will return a list of all indexes you need.

P.S. Hugh's answer shows a generator function (it makes a difference if the list of indexes can get large). This function can also be adjusted by changing [] to ().

Answer from Lev Levitsky on Stack Overflow
🌐
Delft Stack
delftstack.com › home › howto › python › python find all indexes of a character in string
How to Find All Indexes of a Character in Python String | Delft Stack
February 2, 2024 - We can use regular expressions, the yield keyword, and list comprehensions to find all the indexes of a character inside a string in Python.
Discussions

How to find all occurrences of a substring in a string while ignore some characters in Python?
You could use re for this. ex import re long_string = 'this is a t`es"t. Does the test work?' small_string = "test" chars_to_ignore = ['"', '`'] print(re.findall(f"[{''.join(chars_to_ignore)}]*".join(small_string), long_string)) More on reddit.com
🌐 r/learnpython
6
1
July 25, 2024
python - Finding All Positions Of A Character In A String - Stack Overflow
I'm trying to find all the index numbers of a character in a python string using a very basic skill set. For example if I have the string "Apples are totally awesome" and I want to find the places ... More on stackoverflow.com
🌐 stackoverflow.com
September 22, 2018
python - How to find all occurrences of a substring? - Stack Overflow
-2 Python - How to find 'repeat' characters in a string? 1 How to get multipleindices of a word which is occurring more than once in a string? 2 How to find all the indexes of all the occurrences of a substring in a string More on stackoverflow.com
🌐 stackoverflow.com
January 12, 2011
python - Find all the occurrences of a character in a string - Stack Overflow
@Goodword:This answer uses a list comprehension; see the Python tutorial. 2016-06-01T23:43:00.033Z+00:00 ... R. Wayne Over a year ago · The function is spelled wrong on the definition line. It should be "def findOccurrences" with two r's. 2018-02-04T00:20:05.663Z+00:00 ... import re example_string = "aaaaaa|bbbbbb|ccccc|dddd" indexes ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
EyeHunts
tutorial.eyehunts.com › home › python find all indexes of character in a string | example code
Python find all indexes of character in a string | Example code
November 8, 2021 - Just use for-loop and if statement logic to get done this task. Simple example code finds all occurrence index of “s” char in a given string. text = 'Python is easy programing language' s = 's' res = [] for i in range(len(text)): if text[i] ...
🌐
Bobby Hadz
bobbyhadz.com › blog › python-find-indices-of-all-occurrences-of-character-in-string
Find all occurrences of a Substring in a String in Python | bobbyhadz
Check if each character starts with the given substring and return the result. ... Copied!string = 'bobby hadz bobbyhadz.com' indexes = [ index for index in range(len(string)) if string.startswith('bobby', index) ] print(indexes) # 👉️ [0, 11]
🌐
Built In
builtin.com › software-engineering-perspectives › python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
If start and end parameters are mentioned, it will search the substring within the start and endindex. It will return -1 if the substring is not found. ... An illustration of how the str.find() method works in Python.
🌐
YouTube
youtube.com › shorts › QihabgI6ju0
Find all indexes of char in string using Python #coding #python #programming - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published   December 10, 2025
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-characters-index-occurrences-in-string
Python - Characters Index occurrences in String - GeeksforGeeks
April 23, 2023 - # Python3 code to demonstrate working of # Characters Index occurrences in String # Using regex + set() + list comprehension + replace() import re # initializing string test_str = "Gfg is best for geeks" # printing original string print("The original string is : " + test_str) # Characters Index occurrences in String # Using regex + set() + list comprehension + replace() temp = set(test_str.replace(' ', '')) res = {ele: [sub.start() for sub in re.finditer(ele, test_str)] for ele in temp} # printing result print("Characters frequency index dictionary : " + str(res))
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-all-occurrences-of-substring-in-string
Python - All occurrences of substring in string - GeeksforGeeks
July 12, 2025 - Extract start positions: A list comprehension is used to extract the starting position of each match using match.start(). Using str.find() in a loop allows to find all occurrences of a substring by repeatedly searching for the next match starting ...
🌐
Quora
quora.com › How-do-I-find-the-index-of-a-character-in-a-string-in-Python
How to find the index of a character in a string in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Tu-delft-dcc
tu-delft-dcc.github.io › Intro-to-Python-for-GIS › Instructor_notes › Day_1 › lesson_notes › B2_Vars_Types.html
Use an index to get a single character from a string. — Python essentials for GIS learners
The characters (individual letters, numbers, and so on) in a string are ordered. For example, the string 'AB' is not the same as 'BA'. Because of this ordering, we can treat the string as a list of characters. Each position in the string (first, second, etc.) is given a number. This number is called an index or sometimes a subscript.
🌐
Sololearn
sololearn.com › en › Discuss › 2144485 › is-it-possible-to-find-the-index-of-all-occurrences-of-a-substring-in-a-a-string-in-python
Is it possible to find the index of all occurrences of a substring in a a string in python? | Sololearn: Learn to code for FREE!
You can use the string method 'find'. It gives you the index of the found string. You can tell it where to start looking. Then write a little loop, find all the indexes and put them in a list. Nice little practice task.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
How can I find all indices where a substring appears in a string? - Python FAQ - Codecademy Forums
October 30, 2018 - Answer In this exercise, we were introduced to the .find() method, but it will only return the first index where the substring appears in a string. To obtain all the indices where a substring appears, you can use a loop to iterate over the entire ...
🌐
IncludeHelp
includehelp.com › python › find-all-the-indexes-of-all-the-occurrences-of-a-word-in-a-string.aspx
Find all the indexes of all the occurrences of a word in a string in Python
April 27, 2025 - Learn how to find all the indexes of a word's occurrences in a string in Python. Explore techniques using find(), index(), and list comprehensions for efficient searching.
🌐
datagy
datagy.io › home › python posts › python strings › python: find an index (or all) of a substring in a string
Python: Find an Index (or all) of a Substring in a String • datagy
December 20, 2022 - The above examples both returned ... indices of a substring in a Python string. For this, we’ll use the popular regular expression library, re....
🌐
Hashnode
codingwithestefania.hashnode.dev › python-string-indexing-how-to-get-characters
Python String Indexing - How to Get Individual Characters
February 22, 2024 - We can use the index to access its corresponding character. ... You may find two plural versions of the word index: "indices" or "indexes". They are both commonly used. In the diagram below, you can see an example of the internal "grid" for the string "Code": You may have noticed from this diagram that indices start from 0 in Python.