Question 206 of 511
StringseasyMultiple SelectObjective-mapped

Quick Answer

The answer is the index() and rindex() methods, both of which raise a ValueError exception when the searched substring is not found. This behavior stems from their design as strict search tools: unlike find() and rfind(), which return -1 to signal a missing substring, index() and rindex() are intended for situations where the substring must exist, so they throw an exception to halt execution immediately. On the Certified Associate Python Programmer PCAP exam, this distinction tests your understanding of Python’s exception handling versus sentinel values, often appearing in questions that ask you to identify which string methods raise exceptions for missing substrings. A common trap is confusing index() with find() because they share similar syntax, but remember: index and rindex are the “angry” methods that raise an exception, while find and rfind are the “polite” ones that return -1. For a quick memory tip, think of the letter “i” in index as standing for “interrupt” — when the substring is missing, it interrupts your program with an error.

PCAP Strings Practice Question

This PCAP practice question tests your understanding of strings. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Which TWO string methods raise an exception when the searched substring is not found?

Question 1easymulti select
Full question →

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

rindex()

Option C (rindex()) is correct because the rindex() method, like index(), raises a ValueError exception when the searched substring is not found. This is in contrast to rfind() and find(), which return -1 instead of raising an exception.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • rfind()

    Why it's wrong here

    rfind() returns -1 when substring is not found, not an exception.

  • find()

    Why it's wrong here

    find() returns -1 when substring is not found, not an exception.

  • rindex()

    Why this is correct

    rindex() raises ValueError if substring is not found.

    Related concept

    Read the scenario before looking for a memorised answer.

  • count()

    Why it's wrong here

    count() returns 0 when substring is not found, not an exception.

  • index()

    Why this is correct

    index() raises ValueError if substring is not found.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the distinction between methods that return -1 (find, rfind) versus those that raise an exception (index, rindex), and the trap is that candidates confuse rfind() with rindex() because both perform a right-to-left search.

Detailed technical explanation

How to think about this question

The index() and rindex() methods are part of Python's string sequence protocol, designed to raise a ValueError to signal an absence that may indicate a logical error in the program, whereas find() and rfind() are more forgiving for conditional searches. Under the hood, index() and rindex() call the same underlying C-level search routine as find() and rfind(), but wrap the result with an explicit exception check. In real-world code, using index() is preferred when a missing substring should be treated as an exceptional condition, such as when parsing a required delimiter in structured data.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A cloud solutions architect for a retail company is evaluating services for a new workload. The correct answer here reflects best practice for the specific scenario described — not a general cloud recommendation. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Cloud exam questions reward reading the constraint carefully: the same technology can be right or wrong depending on the use case.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCAP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCAP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCAP question test?

Strings — This question tests Strings — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: rindex() — Option C (rindex()) is correct because the rindex() method, like index(), raises a ValueError exception when the searched substring is not found. This is in contrast to rfind() and find(), which return -1 instead of raising an exception.

What should I do if I get this PCAP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More PCAP practice questions

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.