A non-slicky method:

def index_containing_substring(the_list, substring):
    for i, s in enumerate(the_list):
        if substring in s:
              return i
    return -1
Answer from kennytm on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-the-index-of-a-substring-in-python
Find the Index of a Substring in Python - GeeksforGeeks
July 23, 2025 - The substring 'for' is found at index 6. The re.search() in Python's re module can be used to locate the first occurrence of a pattern in a string.
Discussions

python - How to find indexes of string in lists which starts with some substring? - Stack Overflow
And I want to take list of index of lines which starts with some substring. ... That's look pretty Pythonic to me. More on stackoverflow.com
🌐 stackoverflow.com
Index of substring in a python list of strings - Stack Overflow
How can I extract the index of a substring in a python list of strings (preferentially in a rapid way to handle long lists)? For example, with mylist = ['abc', 'day', 'ghi'] and character 'a', I w... More on stackoverflow.com
🌐 stackoverflow.com
October 8, 2018
Python get index of list in list of lists that contains a substring - Stack Overflow
I have a list that looks like this: lst = [['Apple Pie', 'Carrot Cake'], ['Steak', 'Chicken']] I would like to find the index of the list that contains the word ' Carrot', so in this case, the out... More on stackoverflow.com
🌐 stackoverflow.com
python - Finding substring in list of strings, return index - Stack Overflow
4 Pythonic way of searching for a substring in a list · 15 How to find indexes of string in lists which starts with some substring? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Programiz
programiz.com › python-programming › methods › string › index
Python String index()
The index() method returns the index of a substring inside the string (if found).
🌐
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 - We include the index position of that number if the substring that’s created by splitting our string from that index onwards, begins with our letter · We get a list returned of all the instances where that substring occurs in our string · In the final section of this tutorial, you’ll learn how to build a custom function to return the indices of all substrings in our Python string.
🌐
Built In
builtin.com › software-engineering-perspectives › python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
re.search(): This returns None when a substring is not found. The index() method in Python finds the first occurrence of a specific character or element in a string or list. If the character or element is found, its index value will be returned.
🌐
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
If we take the following lists: Original List: ["HelloWorld", "LearningPython", "GoForBroke", "BackToBasics"] Substring List: ["loW", "ear", "o", "Ba"]. This will produce the following outputs: In "HelloWorld", "loW" starts at index 3. In "LearningPython", "ear" starts at index 1.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
September 29, 2025 - Key Differences: The distinction between indexing (which returns a single character and raises an IndexError if out of bounds) and slicing (which returns a substring and gracefully handles out-of-bounds requests by returning an empty string). String Reversal: The efficient and Pythonic way to reverse a string using the [::-1] slice.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
1 month ago - If you need to match a substring inside list elements, see the section on Searching for a substring within list elements. For more on the string formatting used here, see f-strings in Python. When you need the position of a string instead of a yes/no answer, use the list index() method.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-extract-indices-of-substring-matches
Python - Extract Indices of substring matches - GeeksforGeeks
May 5, 2023 - In this, we perform the similar task as above method using list comprehension and enumerate() is used to get compact solution. ... # Python3 code to demonstrate working of # Extract Indices of substring matches # Using list comprehension + enumerate() # initializing list test_list = ["Gfg is good", "for Geeks", "I love Gfg", "Its useful"] # initializing K K = "Gfg" # printing original list print("The original list : " + str(test_list)) # using list comprehension and enumerate to offer compact solution res = [idx for idx, val in enumerate(test_list) if K in val] # printing result print("The indices list : " + str(res))
🌐
Python Tutorial
pythontutorial.net › home › python string methods › python string index()
Python String index(): Locating the Index of a Substring in a String
December 28, 2020 - The following example uses the index() method to find the substring 'Python' in the string 'Python will, Python will rock you.' within the slice str[1:]:
🌐
Medium
medium.com › @muraliairody › find-and-index-of-string-6c50c819273c
Find and Index of String
October 24, 2025 - Works like find() — returns the lowest index of the substring. But if the substring is not found, it raises a ValueError instead of returning -1. ... text = "Hello Python" print(text.index("Python")) # 6 # print(text.index("Java")) # ValueError: substring not found
🌐
Better Programming
betterprogramming.pub › 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 - Listen · Share · Press enter ... str.index() str.rindex() re.search() 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. ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-index-method
Python String index() Method - GeeksforGeeks
May 2, 2025 - Explanation: index() method searches for the substring "prog" within "Python programming" and returns starting index 7.
🌐
Vultr Docs
docs.vultr.com › python › standard-library › str › index
Python str index() - Find Substring Index | Vultr Docs
November 26, 2024 - The index() method in Python is a useful string method for finding the starting index of a substring within a string. This method raises an exception if the substring is not found, making it distinguishable from similar methods like find(), ...
🌐
Reddit
reddit.com › r/learnpython › how to get what index position the last character of a string is
r/learnpython on Reddit: how to get what index position the last character of a string is
April 2, 2022 -

Hey. I'm trying to get the index position of the last character in a string. For example, if the string is "Hello" , I want the program to only print that the last character (in this case 'o') is in index position 4. The string would be inputted by the user though so its always going to be different.

I'm familiar with (len(string)) and string[-1] but not sure how to use them together, if I even need to.