Courseiva
Strings →mediumMultiple Choice

PCAP Strings Practice Question

What is the result of 'Python'.find('th')?

⚠ Common exam trap

Python Institute often tests the zero-based indexing of strings, leading candidates to mistakenly count from 1 instead of 0, or to confuse `find()` with `index()` and expect an exception for missing substrings.

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

✓

2

The string method `find()` returns the lowest index where the substring is found. In 'Python', the substring 'th' starts at index 2 (P=0, y=1, t=2, h=3, o=4, n=5). Therefore, the result is 2, making option C 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.

  • ✗

    1

    Why it's wrong here

    The value 1 points to the second character of 'python', which is 'y', not the 't' that begins the target substring 'th'. str.find returns the starting index of the first complete match, and at index 1 the following characters are 'yo', so this position cannot be the match location. Thus 1 is an incorrect answer.

  • ✗

    -1

    Why it's wrong here

    -1 is str.find's sentinel for 'substring not found', but 'th' is clearly present as characters 't' and 'h' at positions 2 and 3 of 'python'. Since the method locates a match, its return value must be a non-negative integer, and the absence sentinel -1 is never returned when a match exists. Therefore -1 is incorrect.

  • ✓

    2

    Why this is correct

    Indexing 'python' from zero gives p=0, y=1, t=2, h=3, o=4, n=5; the two-character substring 'th' begins at offset 2, where 't' resides and is followed immediately by 'h'. Python's str.find returns the lowest zero-based index at which the substring starts, so 'python'.find('th') evaluates to exactly 2. This is the correct result.

  • ✗

    0

    Why it's wrong here

    A return value of 0 would mean the substring starts at the first character, so 'python' would need to begin with 'th', but it actually begins with 'py'. str.find is not a boolean indicator or a count of positions inspected; it directly yields the matching index, and no character comparison at offset 0 involves 't'. Hence 0 cannot be the correct result.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.