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 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
python 2.7 - Finding the Index of a character within a string - Stack Overflow
This may be worded incorrectly because I'm a wee beginner, but if I have a string how to I find a certain characters index like you can with the .index thing in lists. With a list it makes sense: ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to find char in string and get all the indexes? - Stack Overflow
-1 I'm stuck in getting the index position of a character in a string in Python that is present more than once in the string More on stackoverflow.com
🌐 stackoverflow.com
Find a character position within string
The index given is always relative to the original string. >>> "abcdec".find("c") 2 >>> "abcdec".find("c", 1) 2 >>> "abcdec".find("c", 3) 5 More on reddit.com
🌐 r/learnpython
22
14
March 24, 2025
🌐
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()
sentence = 'Python programming is fun.' # Substring is searched in 'gramming is fun.' print(sentence.index('ing', 10)) # Substring is searched in 'gramming is ' print(sentence.index('g is', 10, -4)) # Substring is searched in 'programming' ... 15 17 Traceback (most recent call last): File "<string>", line 10, in print(quote.index('fun', 7, 18)) ValueError: substring not found
🌐
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.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string find() with examples
Python String find() with Examples - Spark By {Examples}
May 21, 2024 - Python String find() function is used to find the index position of the first occurrence of the character or the first occurrence of the String or the first occurrence from the specified position etc.
🌐
Hashnode
codingwithestefania.hashnode.dev › python-string-indexing-how-to-get-characters
Python String Indexing - How to Get Individual Characters
February 22, 2024 - We can use the index to access its corresponding character. ... You may find two plural versions of the word index: "indices" or "indexes". They are both commonly used. In the diagram below, you can see an example of the internal "grid" for the string "Code": You may have noticed from this diagram that indices start from 0 in Python...
Find elsewhere
🌐
YouTube
youtube.com › shorts › WQkb2cUnrDE
How To Find The Index Of A Character In A String In Python - YouTube
In this python tutorial, I show you how to find the index of a character in a string in python. Let's get coding!======== Ask Case Digital ========If you hav...
Published   December 20, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-find-position-of-a-character-in-given-string
Find position of a character in given string - Python - GeeksforGeeks
July 11, 2025 - The index() method returns the index of the first occurrence of a character. If not found, it raises a ValueError. ... If the character isn’t found, it raises an error-handled using try-except.
🌐
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.

🌐
PyTutorial
pytutorial.com › find-character-index-in-python-string-guide
PyTutorial | Find Character Index in Python String | Guide
February 23, 2026 - It is perfect for checking if a character exists. Here is the basic syntax: string.find(sub, start, end). The 'sub' is the character to find. 'start' and 'end' define the search range.
🌐
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.
🌐
Delft Stack
delftstack.com › home › howto › python › position of character in string
How to Find Character in a String in Python | Delft Stack
February 12, 2024 - The function returns the index of the first occurrence of the specified item, and the search starts from the beginning of the string. ... The variable s is assigned the string python is fun, and the variable c is assigned the character n.
🌐
Educative
educative.io › answers › how-to-get-the-characters-in-a-string-in-python
How to get the character(s) in a string in Python
You can use a negative index starting from the end of a string to get the character of a string, as shown below. ... In the example below, you can use the same syntax to extract a few characters instead of just one. ... When you use the syntax print(Name[0:]), Python will assume the indexes from zero to the last index by default.
🌐
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