There are two string methods for this, find() and index(). The difference between the two is what happens when the search string isn't found. find() returns -1 and index() raises a ValueError.

Using find()

>>> myString = 'Position of a character'
>>> myString.find('s')
2
>>> myString.find('x')
-1

Using index()

>>> myString = 'Position of a character'
>>> myString.index('s')
2
>>> myString.index('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: substring not found

From the Python manual

string.find(s, sub[, start[, end]])
Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.

And:

string.index(s, sub[, start[, end]])
Like find() but raise ValueError when the substring is not found.

Answer from Eli Bendersky on Stack Overflow
๐ŸŒ
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). If the substring is not found, it raises an exception. ... If substring exists inside the string, it returns the lowest index in the string where substring is found. If substring doesn't exist inside the string, ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Bootcamp Python Training ... The index() method finds the first occurrence of the specified value....
Discussions

how to get what index position the last character of a string is
this could have been solved with 5 minutes of experimentation if you're going to be a programmer you have to start experimenting with code, just test and try stuff out More on reddit.com
๐ŸŒ r/learnpython
13
3
April 2, 2022
Add a `count` keyword to str.index and str.find to find the n-th occurence of an element in a string
Current signature: str.index(sub[, start[, end]]) New suggested signature: str.index(sub[, start[, end[, count]]]) Str.index returns the countth occurence. By default count is of course 1. EDIT: Removed getting the nth column from a TSV example as it derailed the discussion. More on discuss.python.org
๐ŸŒ discuss.python.org
17
0
August 8, 2023
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
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.
๐ŸŒ
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
๐ŸŒ
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. ... end (optional): The ending index for the search. If not provided, it defaults to the length of the string.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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 - Letโ€™s see how we can use the str.rindex() method to find the last index of a substring in Python: a_string = "the quick brown fox jumps over the lazy dog.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ string_index.htm
Python String index() Method
Welcome to Tutorialspoint." str2 ... above program - ... The python string index() method returns the index where the substring is found within the range of the starting and ending index that is specified....
๐ŸŒ
Toppr
toppr.com โ€บ guides โ€บ python-guide โ€บ references โ€บ methods-and-functions โ€บ methods โ€บ string โ€บ index โ€บ python-string-index
Python index() function | Why do we use Python String index() function? |
September 27, 2021 - Python index() built-in function is used to return the index value of the first occurrence of a substring from the input string if the substring is found. If the substring specified is not found, then it raises an exception.
๐ŸŒ
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 - Since the string has two substrings 'Python', the index() method returns the lowest index where the substring found in the string. 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:]:
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-find-index-containing-string-in-list
Python - Find Index Containing String in List
August 16, 2023 - When searching for all indices of a particular string value, use this approach ? def find_all_indices(target, search_list): indices = [] start = 0 while True: try: index = search_list.index(target, start) indices.append(index) start = index + 1 except ValueError: break return indices test_list = ["Python", "Java", "Python", "C++", "Python"] result = find_all_indices("Python", test_list) print(f"All indices of 'Python': {result}")
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard-library โ€บ str โ€บ index
Python str index() - Find Substring Index | Vultr Docs
November 26, 2024 - Set these parameters to define the desired slice of the string for the search. ... full_string = "Hello, welcome to Python. Welcome again!" substring = "welcome" limited_search = full_string.index(substring, 10) # Start searching from index 10 print(limited_search) Explain Code
๐ŸŒ
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
๐ŸŒ
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.

๐ŸŒ
Medium
medium.com โ€บ @muraliairody โ€บ find-and-index-of-string-6c50c819273c
Find and Index of String
October 24, 2025 - Optional start and end parameters let you search within a slice of the string. ... text = "Hello Python" print(text.find("Python")) # 6 print(text.find("Java")) # -1 print(text.find("o")) # 4 (first occurrence) ... 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.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Add a `count` keyword to str.index and str.find to find the n-th occurence of an element in a string - Python Help - Discussions on Python.org
August 8, 2023 - Current signature: str.index(sub[, start[, end]]) New suggested signature: str.index(sub[, start[, end[, count]]]) Str.index returns the countth occurence. By default count is of course 1. EDIT: Removed getting the โ€ฆ
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ list โ€บ index
Python List index()
Python String rindex() The index() method returns the index of the specified element in the list. animals = ['cat', 'dog', 'rabbit', 'horse'] # get the index of 'dog' index = animals.index('dog') print(index) # Output: 1 ยท The syntax of the list index() method is: list.index(element, start, ...