str.find returns -1 when it does not find the substring.

>>> line = 'hi, this is ABC oh my god!!'
>>> line.find('?')
-1

While str.index raises ValueError:

>>> line.index('?')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: substring not found

Both the functions behave the same way if a sub-string is found.

Answer from falsetru on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-find-and-index-in-python
Difference Between find() and index() in Python - GeeksforGeeks
July 23, 2025 - Both methods are used to locate the position of a substring within a string but the major difference between find() and index() methods in Python is how they handle cases when the substring is not found.
Discussions

Why use index over find?
Why would you use either of them? More on reddit.com
🌐 r/learnpython
18
8
March 4, 2025
Help with .index()? finding multiple instances of item
The easy way would be to just use enumerate on the list, and then manually iterate the list and find the indices yourself. More on reddit.com
🌐 r/learnpython
9
3
March 11, 2023
🌐
Quora
quora.com › What-is-the-difference-between-index-and-find-in-Python
What is the difference between index and find in Python? - Quora
Answer (1 of 2): index() is the method used in list which returns the lowest index in list that obj appears. If not found it will raise an exception indicating that value does not find. [code]aList = [123, 56.88, 'Python', True] print(aList.index(56.88)) [/code]prints 1 [code]print(aList.index(...
🌐
Just Academy
justacademy.co › blog-detail › difference-between-find-and-index-in-python
Difference Between Find And Index In Python by Roshan Chaturvedi | JustAcademy
April 9, 2024 - The key difference between the two is how they handle scenarios where the substring is not found. The `find()` method returns -1 if the substring is not found, whereas the `index()` method raises a ValueError exception.
🌐
Medium
allwin-raju.medium.com › understanding-the-difference-between-find-and-index-in-python-365afe069dec
Understanding the Difference Between find() and index() in Python | by Allwin Raju | Medium
December 21, 2024 - Python provides two built-in methods to achieve this: find() and index(). While they might seem similar at first glance, they have distinct behaviours that suit different use cases. In this post, we’ll explore the differences between these methods and when to use each one.
🌐
Educative
educative.io › answers › what-is-the-difference-between-string-find-and-index-method
What is the difference between String find() and index() method?
Python provides the following two built-in methods to find the first occurrence of a given substring in a string: ... Both methods have the same syntax. However, in the case where the required substring is not found in the target string, there is a significant difference in the output of both ...
Find elsewhere
🌐
CodeSpeedy
codespeedy.com › home › difference between find() and index() in python
Difference between find() and index() in Python - CodeSpeedy
July 15, 2020 - Just like find(), index() method determines the position at which a substring is first found in a string. In the same way index() takes 3 parameters: substring that is to be searched, index of start and index of the end(The substring is searched between the start and end indexes of the string) out of which indexes of start and end are optional.
🌐
Just Academy
justacademy.co › public › blog-detail › difference-between-find-and-index-in-python
Difference Between Find And Index In Python
The key difference between the two is how they handle scenarios where the substring is not found. The `find()` method returns -1 if the substring is not found, whereas the `index()` method raises a ValueError exception.
🌐
Talkerscode
talkerscode.com › howto › difference-between-find-and-index-in-python.php
Difference Between Find And Index In Python
We then use the find() method to check if the substring is present in the string. The find() method will return -1 if the substring is not present in the string. We then use the index() method to check if the substring is present in the string.
🌐
Plain English
python.plainenglish.io › pythons-find-and-index-functions-a-comprehensive-guide-c7dba18cc59d
Python’s find() and index() Functions: A Comprehensive Guide | by Durgesh Samariya | Python in Plain English
September 20, 2023 - The find() function is used to locate the first occurrence of a substring within a given string. It returns the index of the first character of the first occurrence of the substring.
🌐
CSEstack
csestack.org › home › difference between index() and find() in python
Difference between index() and find() in Python
July 9, 2020 - Note: The index() method can also be used to search the element in the Python list. ... We will use the same string and sub-string for find() method. samp_str = "CSEstack programmer" print(samp_str.find('stack')) ... You will find the same output result. Is there any difference between index() and find()?
🌐
Brainly
brainly.in › computer science › secondary school
Difference between index and find function in python - Brainly.in
February 13, 2024 - The difference between index and find functions in Python is that index raises an exception if the substring is not found in the string, while find returns -1 in that case.
🌐
Iditect
iditect.com › programming › python-example › difference-between-find-and-index-in-python.html
Difference Between find( ) and index( ) in Python
s = "hello" result = s.index("l") ... not found in string.") # This block will be executed ... Use find() if you want a simple way to check for the presence of a substring in a string and don't want to handle exceptions....
🌐
TheLinuxCode
thelinuxcode.com › home › difference between find() and index() in python (practical patterns, pitfalls, and 2026-style error handling)
Difference Between find() and index() in Python (Practical Patterns, Pitfalls, and 2026-Style Error Handling) – TheLinuxCode
February 1, 2026 - If you remember only one thing, remember this: find() makes failure easy to ignore; index() makes failure hard to ignore. The most expensive bugs here aren’t about forgetting the difference between -1 and ValueError. The expensive bugs happen when someone checks the returned integer in a way that doesn’t match how integers behave in Python.
🌐
YouTube
youtube.com › shorts › DF5nT-JMPHI
Do YOU Know When to use FIND or INDEX - YouTube
In this python tutorial, I discuss the difference of Index vs Find in finding the substring index. Let's get coding!======== Ask Case Digital ========If you ...
Published: December 21, 2024
🌐
w3reference
w3reference.com › blog › python-why-do-the-find-and-index-methods-work-differently
Python: Why Do find() and index() Methods Behave Differently? Key Differences Explained — w3reference.com
Fails-Fast Behavior: index() raises an error immediately, which is useful when the substring must exist (e.g., parsing structured data like "YYYY-MM-DD" where "-" is expected). You need to check for the presence of a substring and handle its absence gracefully (without exceptions). Scenario: Searching for a keyword in user input. user_input = "I love Python programming" keyword = "Python" if user_input.find(keyword) != -1: print(f"Keyword '{keyword}' found!") else: print(f"Keyword '{keyword}' not found.")
🌐
Sololearn
sololearn.com › en › Discuss › 3020428 › what-is-the-difference-between-find-and-index-in-python
What is the difference Between find( ) and index( ) in Python? | Sololearn: Learn to code for FREE!
Quoted from https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_find.asp "The find() method is almost the same as the index() method, the only difference is that the index() method raises an exception if the value is not found."