Question 218 of 511
StringsmediumMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is to use re.search(r'\bexcellent\b', review, re.IGNORECASE) because the \b word boundary anchor ensures that only the whole word 'excellent' is matched, preventing false positives from substrings like 'unexcellent' or 'excellently'. The re.IGNORECASE flag handles case variations such as 'Excellent' or 'EXCELLENT', while the word boundary naturally accounts for adjacent punctuation like 'excellent!' by matching the transition between a word character and a non-word character. On the Certified Associate Python Programmer PCAP exam, this question tests your understanding of regular expression anchors and flags, a common topic in the string operations and pattern matching domain. A frequent trap is using 'excellent' in review.lower() which fails on substrings, or forgetting re.IGNORECASE and missing uppercase variants. Remember the mnemonic: "Boundaries block bad bits" — \b blocks partial matches, and IGNORECASE catches all cases.

PCAP Strings Practice Question

This PCAP practice question tests your understanding of strings. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. 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.

You are a data analyst working with a dataset of customer reviews. Each review is stored as a string in a list. You need to count how many reviews contain the word 'excellent' (case-insensitive). However, the word might appear as 'Excellent', 'EXCELLENT', or even with punctuation like 'excellent!'. The current code uses 'excellent' in review.lower(), but this fails if 'excellent' is part of another word like 'unexcellent'. You need to ensure that only the whole word 'excellent' is counted. Which code modification will correctly count whole word occurrences?

Question 1mediummultiple choice
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

Use re.search(r'\bexcellent\b', review, re.IGNORECASE)

Option A is correct because `re.search(r'\bexcellent\b', review, re.IGNORECASE)` uses the `\b` word boundary anchor to ensure that 'excellent' is matched as a whole word, not as part of another word like 'unexcellent'. The `re.IGNORECASE` flag handles case-insensitive matching, covering 'Excellent', 'EXCELLENT', etc. This approach also correctly handles punctuation attached to the word, such as 'excellent!', because the word boundary matches between a word character and a non-word character.

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.

  • Use re.search(r'\bexcellent\b', review, re.IGNORECASE)

    Why this is correct

    Word boundary regex ensures whole word match regardless of case.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use 'excellent' in review.lower().split()

    Why it's wrong here

    split() splits on whitespace, but punctuation like 'excellent!' will not match exactly 'excellent'.

  • Use review.lower().count('excellent') > 0

    Why it's wrong here

    count() counts overlapping? Actually count counts non-overlapping, but still counts inside words like 'unexcellent'.

  • Use review.lower().find('excellent') != -1

    Why it's wrong here

    find() returns index if substring exists anywhere, including inside words.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the distinction between substring matching and whole-word matching, and the trap here is that candidates assume `in` with `split()` or `count()` handles whole words, but they fail to account for punctuation or compound words, leading to incorrect counts.

Detailed technical explanation

How to think about this question

The `\b` word boundary in regex matches at a position between a word character (alphanumeric or underscore) and a non-word character, or at the start/end of the string. This is defined by the Unicode or ASCII word character set depending on the regex engine. In Python's `re` module, `re.IGNORECASE` performs case-insensitive matching by converting both the pattern and the string to lowercase internally, but it does not affect word boundaries. A real-world scenario is sentiment analysis on social media data where words like 'excellent' may appear with hashtags (#excellent) or in compound words, and word boundaries ensure accurate counting.

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: Use re.search(r'\bexcellent\b', review, re.IGNORECASE) — Option A is correct because `re.search(r'\bexcellent\b', review, re.IGNORECASE)` uses the `\b` word boundary anchor to ensure that 'excellent' is matched as a whole word, not as part of another word like 'unexcellent'. The `re.IGNORECASE` flag handles case-insensitive matching, covering 'Excellent', 'EXCELLENT', etc. This approach also correctly handles punctuation attached to the word, such as 'excellent!', because the word boundary matches between a word character and a non-word character.

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.