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....
🌐
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.
🌐
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.
🌐
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)....
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › string_index.htm
Python String index() Method
The python string index() method is used to return the index of the input string where the substring is found. Basically, it helps us to find out if the specified substring is present in the input string.
🌐
Tutorial Teacher
tutorialsteacher.com › python › string-index
Python string.index() Method (With Examples)
Regex in Python · Create GUI using Tkinter · Entity Framework Extensions - Boost EF Core 9 · Bulk Insert · Bulk Delete · Bulk Update · Bulk Merge · The index() method returns the index of the first occurence of a substring in the given string.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-index-and-slice-strings-in-python
How to Index and Slice Strings in Python? - GeeksforGeeks
July 15, 2025 - String Indexing allows us to access individual characters in a string. Python treats strings like lists where each character is assigned an index, starting from 0.
🌐
Linode
linode.com › docs › guides › how-to-slice-and-index-strings-in-python
How to Slice and Index Strings in Python | Linode Docs
January 28, 2022 - Python strings work like arrays. Individual characters within the string can be retrieved using a zero-based indexing system. This means the first character in an n-length string has position 0 and the final character has the index n - 1. To ...
🌐
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 - In this tutorial, you'll learn how to use the Python string index() method to get the lowest index of a substring in a string.
🌐
IONOS
ionos.com › digital guide › websites › web development › python string index
How to find the position of a substring with Python string index
January 23, 2024 - Python string index lets you find the position of a substring in a string. Here’s how the method works and what it offers.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-string.html
Python Strings
Similarly, if the start index is greater or equal to the end index, the slice is just the empty string. >>> s = 'Python' >>> s[2:999] 'thon' >>> s[3:2] # zero chars ''
🌐
CodeHS
codehs.com › tutorial › 13725
Tutorial: Indexing Python Strings | CodeHS
Learn how to access specific items by indexing through Python strings.
🌐
Spark Code Hub
sparkcodehub.com › python › data › string indexing
Mastering Python String Indexing: A Comprehensive Guide ...
String indexing is a fundamental concept in Python that allows you to access individual characters within a string. As strings are ordered sequences of characters, indexing provides a precise way to retrieve or manipulate specific parts of text.
🌐
Real Python
realpython.com › videos › string-indexing
String Indexing (Video) – Real Python
Indexing allows you to access individual characters in a string directly by using a numeric value. String indexing is zero-based: the first character in the string has index 0, the next is 1, and so on.
Published: October 1, 2019
🌐
Manifoldapp
cuny.manifoldapp.org › read › how-to-code-in-python-3 › section › 93337ae8-329e-493b-b15a-7fe26f12f037
How To Index and Slice Strings | How To Code in Python 3 | Manifold @CUNY
Any other symbol or punctuation mark, such as *#$&.;?, is also a character and would be associated with its own index number. The fact that each character in a Python string has a corresponding index number allows us to access and manipulate strings in the same ways we can with other sequential data types.