Courseiva
Strings →easyMultiple Select

PCAP Strings Practice Question

Which TWO string methods are used to determine if a string begins or ends with a specified prefix or suffix? (Choose two.)

⚠ Common exam trap

The PCAP exam often tests the distinction between methods that return indices (`find()`, `index()`) versus methods that return booleans (`startswith()`, `endswith()`), and candidates mistakenly choose `find()` or `index()` because they think returning 0 for a prefix match is equivalent to a boolean check.

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

✓

startswith()

The `startswith()` method returns `True` if a string begins with the specified prefix, and `endswith()` returns `True` if a string ends with the specified suffix. Both methods accept a string or a tuple of strings to check against, making them the correct choices for determining prefix or suffix presence.

Answer analysis

Option-by-option breakdown

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

  • ✗

    count()

    Why it's wrong here

    count() returns the number of non-overlapping occurrences of a substring across the entire string, so it yields an integer count rather than a Boolean verdict about position. It cannot tell you whether a string begins or ends with a target, because it does not anchor its search to the edges. Even a zero or nonzero result would require separate edge comparisons, making it the wrong tool for this question.

  • ✓

    startswith()

    Why this is correct

    startswith() is the correct method for a prefix check: it returns True only when the string's beginning exactly matches the specified prefix, and False otherwise. It also accepts a tuple of possible prefixes, as well as optional start and end indices for slicing-like boundaries, making it both expressive and efficient. Because it directly answers 'does this string begin with...?', it is one of the two required methods.

  • ✗

    find()

    Why it's wrong here

    find() locates a substring and returns the lowest index at which it appears, or -1 when it is absent; it therefore returns an integer position, not a Boolean. A prefix check using find() == 0 is possible but fragile: it ignores suffix checks, does not natively support tuple alternatives, and obscures intent. Since it scans the whole string without anchoring to either end, it is not one of the two methods meant for determining start/end boundaries.

  • ✓

    endswith()

    Why this is correct

    endswith() is the correct counterpart to startswith(): it returns True only when the string's terminal characters match the given suffix, and False otherwise. It supports tuple arguments to test several suffixes at once and optional start/end indices to restrict the region being examined. This direct Boolean result is exactly what is needed to determine whether a string ends with a specified substring.

  • ✗

    index()

    Why it's wrong here

    index() behaves like find() but instead of returning -1 for a missing substring it raises a ValueError, so it is a locator method, not a predicate. It returns the numeric position of the substring, which means it cannot express a yes/no answer about whether the string starts or ends with something. Using index() for such a check would require exception handling and manual position comparisons, making it plainly unsuitable for the question.

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.