The correct answer is ['Alice', 'Bob'] because the `re.findall(r'[A-Z][a-z]*', 'Alice and Bob are friends')` call returns a list of all non-overlapping matches of the pattern in the string. The regex `[A-Z][a-z]*` matches any uppercase letter followed by zero or more lowercase letters, so it captures only words that begin with a capital letter—here, 'Alice' and 'Bob'—while ignoring 'and', 'are', and 'friends' since they start with lowercase. On the Certified Associate Python Programmer PCAP exam, this tests your understanding of the `re.findall()` function and character class repetition, often appearing in questions about extracting capitalized names or titles. A common trap is forgetting that `[a-z]*` matches zero lowercase letters, so a lone uppercase letter would also match; another is confusing `re.findall()` with `re.search()`, which returns only the first match. Memory tip: think of `findall` as "find all" — it scans the entire string and returns every match in a list, perfect for grabbing all capitalized words in a sentence.
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.
Exhibit
Refer to the exhibit.
Configuration block:
```python
import re
pattern = r'\b[A-Z][a-z]*\b'
text = "Alice and Bob are friends."
matches = re.findall(pattern, text)
```
Refer to the exhibit.
Configuration block:
```python
import re
pattern = r'\b[A-Z][a-z]*\b'
text = "Alice and Bob are friends."
matches = re.findall(pattern, text)
```
A
['Alice', 'Bob']
Correct matches.
B
['Alice']
Why wrong: Bob also matches.
C
['Alice', 'and', 'Bob', 'are', 'friends']
Why wrong: Only matches starting uppercase.
D
['Alice', 'Bob', 'friends']
Why wrong: 'friends' does not start with uppercase.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
['Alice', 'Bob']
The correct answer is A because the `re.findall(r'[A-Z][a-z]*', 'Alice and Bob are friends')` call matches all sequences starting with an uppercase letter followed by zero or more lowercase letters. This yields 'Alice' and 'Bob', as they are the only words beginning with a capital letter. The result is a list of those two strings.
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.
✓
['Alice', 'Bob']
Why this is correct
Correct matches.
Related concept
Read the scenario before looking for a memorised answer.
✗
['Alice']
Why it's wrong here
Bob also matches.
✗
['Alice', 'and', 'Bob', 'are', 'friends']
Why it's wrong here
Only matches starting uppercase.
✗
['Alice', 'Bob', 'friends']
Why it's wrong here
'friends' does not start with uppercase.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Python Institute often tests the misconception that `[a-z]*` matches any sequence of letters, but the pattern requires the first character to be uppercase, causing candidates to incorrectly include all words or miss the second capitalized word.
Detailed technical explanation
How to think about this question
The regex `[A-Z][a-z]*` uses a character class `[A-Z]` to match any single uppercase letter, followed by `[a-z]*` (zero or more lowercase letters). The `re.findall()` function returns all non-overlapping matches as a list of strings. This pattern is case-sensitive and relies on ASCII letter ranges; it would not match accented uppercase letters like 'É' unless the Unicode flag is used.
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.
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: ['Alice', 'Bob'] — The correct answer is A because the `re.findall(r'[A-Z][a-z]*', 'Alice and Bob are friends')` call matches all sequences starting with an uppercase letter followed by zero or more lowercase letters. This yields 'Alice' and 'Bob', as they are the only words beginning with a capital letter. The result is a list of those two strings.
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 →
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.
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.
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.
Sign in to join the discussion.