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
🌐
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 ... match.start(). Using str.find() in a loop allows to find all occurrences of a substring by repeatedly searching for the next match starting from the last found index....
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
Finding (multiple) positions of a character in a string
I’m trying to code a simple text-based hang-man game, and can’t seem to get over this hump (AKA the middle portion): while True: from random import randint word_list = ['elephant', 'giraffe,', 'snake', 'tiger', 'monkey', 'bird', 'leopard', 'crocodile', 'buffalo', 'mouse', 'wolf', 'pig', ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
6
0
April 3, 2019
How to find indexes of a character in a string
By using find or search we are getting only first index, but i want to get all the indexes of the particular character in a string. community.appian.com/.../how More on community.appian.com
🌐 community.appian.com
1
0
March 26, 2024
Help with .index()? finding multiple instances of item
The easy way would be to just use enumerate on the list, and then manually iterate the list and find the indices yourself. More on reddit.com
🌐 r/learnpython
9
3
March 11, 2023
🌐
W3Schools
w3schools.com › python › ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... The index() method finds the first occurrence of the specified value.
🌐
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.
🌐
Programiz
programiz.com › python-programming › methods › string › index
Python String index()
sentence = 'Python programming is fun.' # Substring is searched in 'gramming is fun.' print(sentence.index('ing', 10)) # Substring is searched in 'gramming is ' print(sentence.index('g is', 10, -4)) # Substring is searched in 'programming' ... 15 17 Traceback (most recent call last): File "<string>", line 10, in print(quote.index('fun', 7, 18)) ValueError: substring not found
Find elsewhere
🌐
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.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Finding (multiple) positions of a character in a string - Curriculum Help - The freeCodeCamp Forum
April 3, 2019 - I’m trying to code a simple text-based hang-man game, and can’t seem to get over this hump (AKA the middle portion): while True: from random import randint word_list = ['elephant', 'giraffe,', 'snake', 'tiger', 'monkey', 'bird', 'leopard', 'crocodile', 'buffalo', 'mouse', 'wolf', 'pig', ...
🌐
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.
🌐
Real Python
realpython.com › python-strings
Strings and Character Data in Python – Real Python
December 22, 2024 - Indexing: Consists of retrieving a given character using its associated index. Slicing: Allows you to get a portion of an existing string using indices. In the following sections, you’ll learn how to run these two operations on your Python strings.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-the-indices-of-all-occurrences-of-an-element-in-a-list
Get the indices of all occurrences of an element in a list - Python - GeeksforGeeks
July 23, 2025 - List comprehension allows for a concise and efficient way to find indices. By iterating through the list enumerate() we can collect the indices where the element matches. The indices are stored in the list of indices.
🌐
Medium
medium.com › better-programming › 5-ways-to-find-the-index-of-a-substring-in-python-13d5293fc76d
5 Ways to Find the Index of a Substring in Python | by Indhumathy Chelliah | Better Programming
September 2, 2021 - str.find() returns the lowest index in the string where the substring sub is found within the slice s[start:end]. It returns -1 if the sub is not found. start and end are optional arguments. -python docs
🌐
Simplilearn
simplilearn.com › home › resources › software development › python index: mastering list indexing techniques
Python List index() Method Explained with Examples
3 weeks ago - The Python index() method helps you find the index position of an element or an item in a string of characters or a list of items.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
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 - s='python' print("Third character is : ",s[2]) print("Seven character is : ",s[7]) # which is not possible for given string ... The index() method finds the first occurrence of the specified value.
🌐
DataCamp
datacamp.com › tutorial › python-string-contains
Python String Search and Replace: in, .find(), .index(), . ...
March 31, 2026 - Edge case: "" in s is always True (the empty string is in every string). str.find() returns the lowest index of the substring, or -1 if not found.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-find-index-containing-string-in-list
Python - Find Index containing String in List - GeeksforGeeks
July 23, 2025 - It involves identifying the position where a specific string appears within the list. index() method in Python is used to find the position of a specific string in a list.
🌐
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]
🌐
Supabase
supabase.com › docs › guides › database › managing tables, views, and data
Tables and Data | Supabase Docs
1 day ago - Without a view, we would need to go into every dependent query to add the new rule. This would increase in the likelihood of errors and inconsistencies, as well as introducing a lot of effort for a developer. With views, we can alter the underlying query in the view transcripts. The change will be applied to all applications using this view.