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

Python - Why do the find and index methods work differently? - Stack Overflow
In Python, find and index are very similar methods, used to look up values in a sequence type. find is used for strings, while index is for lists and tuples. They both return the lowest index (the ... More on stackoverflow.com
🌐 stackoverflow.com
Should I use .find() or index?
A few questions on this one: Why use find instead of .index? I tried the following boolean to achieve the return word if start or end are not in the string. It seems to always come back true. But if I remove the or condition and just use if start not in word then returns false and moves on. ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
0
June 21, 2019
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
🌐
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.
🌐
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.
🌐
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 - Understanding the Difference Between find() and index() in Python When working with strings in Python, locating a substring is a common task. Python provides two built-in methods to achieve this …
🌐
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(...
Find elsewhere
🌐
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 ...
🌐
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.
🌐
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.
🌐
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. If the substring is not found, it returns -1. ... New Python ...
🌐
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.
🌐
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()?
🌐
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....
🌐
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."
🌐
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.")
🌐
TheLinuxCode
thelinuxcode.com › home › difference between find() and index() in python
Difference Between find() and index() in Python – TheLinuxCode
January 27, 2026 - This is not a replacement for find() or index(), but it’s a good option when you want a single split and a clear indicator of presence. Both methods are implemented in optimized C and run in linear time relative to the length of the string. In practice, the difference between them is negligible for typical inputs.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
Should I use .find() or index? - Python FAQ - Codecademy Forums
June 21, 2019 - A few questions on this one: Why use find instead of .index? I tried the following boolean to achieve the return word if start or end are not in the string. It seems to always come back true. But if I remove the or condition and just use if start not in word then returns false and moves on. def substring_between_letters(word,start,end): if start or end not in word: return print(word) else: startPoint = word.index(start) endPoint = word.index(end) return print(word[st...
🌐
All In The Diffrence
allinthedifference.com › difference-between-find-and-index-in-python
Understanding the Key Differences Between Find() and Index() in Python: A Comprehensive Guide
June 25, 2024 - It’s clear that choosing between these two depends largely on your specific needs: if you’re working with larger strings or repetitive tasks where misses might occur, find()’s non-interruptive nature is a godsend; but when certainty of matches is high and speed matters, nothing beats index(). Now armed with this knowledge about their efficiency differences, you’re well-prepared for coding more effective Python projects!