PCAP Strings Practice Question
A developer wants to check if a string contains only alphabetic characters. Which string method should be used?
⚠ Common exam trap
The PCAP exam often tests the distinction between `isalpha()` and `isalnum()`, where candidates mistakenly choose `isalnum()` thinking it checks for letters only, but it actually includes digits as well.
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
✓
isalpha()
The `isalpha()` method returns `True` if all characters in the string are alphabetic (letters) and the string is non-empty. This directly matches the developer's requirement to check for only alphabetic characters.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
isalnum()
Why it's wrong here
isalnum() is incorrect because it returns True whenever every character in the string is alphanumeric, meaning either a letter or a digit. A string like 'abc123' would therefore satisfy isalnum() even though it clearly contains non-alphabetic characters. The task requires rejecting digits, so this method is too permissive for a pure alphabetic check.
- ✗
isspace()
Why it's wrong here
isspace() is incorrect because its sole purpose is to detect whitespace-only strings: it returns True when every character is a space, tab, newline, or other whitespace separator. Such strings contain no alphabetic characters at all, so calling isspace() on ' ' yields True where a pure alphabetic check should return False. It tests the opposite category of content from letters.
- ✓
isalpha()
Why this is correct
isalpha() is correct because it returns True only when the string is non-empty and every character is classified as an alphabetic Unicode character, covering letters like 'A', 'é', and 'α' while rejecting digits, punctuation, and whitespace. This precisely matches the developer's requirement to check if a string contains only alphabetic characters. Note that it is not limited to ASCII, which is useful for internationalized input.
- ✗
isdigit()
Why it's wrong here
isdigit() is wrong because it checks the exact inverse requirement: it returns True only when all characters are decimal digits, such as '0' through '9' or Unicode digit equivalents, so '2024' passes while 'hello' fails. Since the developer needs alphabetic content, isdigit() could never accept a genuinely alphabetical string and is therefore irrelevant to the query.
Go deeper
Related to this question
About these practice questions
One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.