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 - 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
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
🌐
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.
🌐
W3Schools
w3schools.com › python › ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... The index() method finds the first occurrence of the specified value....
🌐
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
We take a slice by using [start:stop], where start is replaced with the index of the first element we want and stop is replaced with the index of the element just after the last element we want. Mathematically, you might say that a slice selects [start:stop). The difference between stop and start is the slice’s length. Taking a slice does not change the contents of the original string. Instead, the slice is a copy of part of the original string. ... Nested functions are evaluated from the inside out, like in mathematics. Python thinks that upper- and lower-case letters are different, so Name and name are different variables.
🌐
DEV Community
dev.to › mohit355 › 4-2-index-and-find-method-python-3ije
4.2 index() and find() method - Python - DEV Community
December 23, 2019 - If start indexing from the last ... time. this is also called negative indexing. Simple answer is by using the index of all the characters in the string....
🌐
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.
🌐
Programiz
programiz.com › python-programming › methods › string › index
Python String index()
The only difference is that find() method returns -1 if the substring is not found, whereas index() throws an exception. ... Substring 'is fun': 19 Traceback (most recent call last): File "<string>", line 6, in result = sentence.index('Java') ValueError: substring not found · Note: Index in ...
🌐
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.