Python String find() Method Explained
Which method returns the lowest index where a specified substring is found, or -1 if not found?
Quick Answer
The answer is the find() method, which returns the lowest index where a specified substring is found, or -1 if the substring is not present. This behavior makes find() the correct choice because it provides a safe way to check for substring existence without raising an exception, unlike the index() method which throws a ValueError when the substring is missing. On the Certified Associate Python Programmer PCAP exam, this distinction between find() and index() is a frequently tested concept, often appearing in questions about string handling and error management. A common trap is confusing find() with index() due to their similar purpose, but the key difference is that find() returns -1 on failure while index() raises an exception. The re module’s search() function is also a distractor, but it returns a match object, not an integer index. For a quick memory tip, remember: "find fails friendly with -1, index throws an exception."
⚠ Common exam trap
The PCAP exam often tests the distinction between `find()` and `index()`, where candidates mistakenly choose `index()` because it returns an index, forgetting that it raises an exception on failure instead of returning -1.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
find()
The `find()` method in Python returns the lowest index where the specified substring is found within the string, or -1 if the substring is not present. This behavior directly matches the question's requirement, making option A correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
find()
Why this is correct
find returns the lowest index or -1 if not found.
- ✗
locate()
Why it's wrong here
locate is not a built-in string method in Python.
- ✗
search()
Why it's wrong here
search is a re module function for regex matching, not a string method.
- ✗
index()
Why it's wrong here
index returns the lowest index but raises ValueError if not found.
Go deeper
Related to this question
About these practice questions
One of 169 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCAP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output?
medium- A.4 followed by error
- ✓ B.4 and -1
- C.4 and 4
- D.-1 and error
Why B: The code searches for the substring 'on' in the string 'Python' twice. The first `find()` call starts from the beginning and finds 'on' at index 4. The second call uses a starting index of 5, which skips the first occurrence, so no 'on' is found after index 5, returning -1. The output is '4 -1', which corresponds to option B.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.