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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A 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
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.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ index
Python String index()
Online Python Online JavaScript ... Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The index() method returns the index of a substring inside the string (if 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. ... end (optional): The ending index for the search. If not provided, it defaults to the length of the string.
๐ŸŒ
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....
๐ŸŒ
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
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ thinkcspy โ€บ Strings โ€บ IndexOperatorWorkingwiththeCharactersofaString.html
9.4. Index Operator: Working with the Characters of a String โ€” How to Think like a Computer Scientist: Interactive Edition
In this case the collection of characters in the string. The index indicates which character you want. It can be any integer expression so long as it evaluates to a valid index value. Note that indexing returns a string โ€” Python has no special type for a single character.
Find elsewhere
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - For example, if we have a string "Hello", we can access the first letter "H" using its index 0 by using the square bracket notation: string[0]. Python's built-in index() function is a useful tool for finding the index of a specific element in a sequence.
๐ŸŒ
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.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ python index: mastering list indexing techniques
Python List index() Method Explained with Examples
July 12, 2026 - 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
๐ŸŒ
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.
๐ŸŒ
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 raises a ValueError because the substring 'Java' doesnโ€™t exist in the string 'Python will, Python will rock you.': s = 'Python will, Python will rock you.' position = s.index('Java') print(position)Code language: PHP (php)
๐ŸŒ
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.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
Learn how to index and slice strings in Python 3 with step-by-step examples. Master substring extraction, negative indexing, and slice notation.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_index.asp
Python List index() Method
Remove List Duplicates Reverse ... Plan Python Interview Q&A Python Training ... The index() method returns the position at the first occurrence of the specified value....
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ python โ€บ string-index
Python string.index() Method (With Examples)
The index() method returns the index of the first occurence of a substring in the given string. It is same as the find() method except that if a substring is not found, then it raises an exception.
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python index: a step-by-step guide
Python Index: A Step-By-Step Guide | Career Karma
December 1, 2023 - Letโ€™s look at the syntax for ... interpreter will return a Python ValueError. index() returns the first instance of an item in a list or a character or phrase in a string....