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
string - Finding a substring within a list in Python - Stack Overflow
import re old_list = ['abc123', ... in new_list: print item ... Why add complexity? The in operator is perfect for the job as seen in other responses. Regexes are a great tool, but I think it's a bit overkill here. 2015-04-24T15:11:49.803Z+00:00 ... Very nifty piece of code. 2018-06-21T16:19:39.413Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 0 Python - find index of unique substring contained ... 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 โ€บ 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.
๐ŸŒ
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.
๐ŸŒ
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.