19+ practice questions focused on Strings — one of the most tested topics on the Certified Associate Python Programmer PCAP exam. Each question includes a detailed explanation so you learn why the right answer is correct.
Start Strings PracticeA developer needs to count the number of occurrences of the substring 'is' in the string 'This is a test. Is this a test?'. Which code correctly performs the count?
Explanation: Option B is correct because Python's string method `count(substring)` returns the number of non-overlapping occurrences of the substring in the string. In 'This is a test. Is this a test?', 'is' appears twice (in 'This' and 'is'), and the method counts them correctly, ignoring case sensitivity (the capitalized 'Is' is not counted).
A programmer writes a function to check if a string is a palindrome (ignoring case and non-alphanumeric characters). Which implementation correctly achieves this?
Explanation: Option B is correct because it first filters the string to keep only alphanumeric characters using `c.isalnum()`, converts the result to lowercase with `.lower()`, and then compares the string to its reverse using slicing `s[::-1]`. This correctly handles case insensitivity and ignores non-alphanumeric characters, which is the standard approach for palindrome checking in Python.
A log analysis script needs to extract all IP addresses from a string. The IPs are in dotted-decimal format. Which regex pattern will correctly extract them?
Explanation: Option C is correct because it uses a non-capturing group `(?:...)` to repeat the pattern `[0-9]{1,3}\.` exactly three times, followed by a final octet `[0-9]{1,3}`. This matches the dotted-decimal structure of an IPv4 address (four octets, each 1–3 digits, separated by dots) without introducing extra spaces or overly permissive digit counts, and it avoids capturing unnecessary groups.
Which string method can be used to check if a string contains only digits?
Explanation: The `str.isdigit()` method returns `True` if all characters in the string are digits (0-9) and the string is non-empty. This is the most direct and commonly used method for checking numeric-only strings in Python, as it specifically tests for digit characters without including other numeric forms like fractions or Roman numerals.
A developer needs to replace all occurrences of 'cat' with 'dog' in a string, but only if 'cat' is a whole word (not part of 'category'). Which code achieves this?
Explanation: Option A uses the `re.sub()` function with the regex pattern `r'\bcat\b'`, where `\b` denotes a word boundary. This ensures that only the whole word 'cat' is matched and replaced with 'dog', ignoring cases where 'cat' appears as part of a larger word like 'category'. The `r` prefix makes it a raw string, preventing escape sequence issues.
+14 more Strings questions available
Practice all Strings questions1. Baseline your knowledge
Start with 10 questions to gauge your current understanding of Strings. This tells you whether you need a concept refresher or just practice.
2. Review every explanation
For each question — right or wrong — read the full explanation. Understanding why an answer is correct is more valuable than knowing the answer itself.
3. Focus on exam traps
Strings questions on the PCAP frequently use trap wording. Look for subtle differences in answers that test your precision, not just general knowledge.
4. Reach 80% consistently
Do repeated sessions until you score 80%+ three times in a row. Then move to mixed-mode practice to test cross-topic recall under realistic conditions.
The exact number varies per candidate. Strings is tested as part of the Certified Associate Python Programmer PCAP blueprint. Practicing with targeted Strings questions ensures you can handle any format or difficulty that appears.
Yes. Courseiva provides free PCAP practice questions across all exam topics and domains. The platform includes topic-based practice, mock exams, missed-question review, bookmarked questions, and readiness tracking — no account required.
Difficulty is subjective, but Strings is a high-priority exam concept tested in multiple ways — direct recall, scenario analysis, and command-output interpretation. Consistent practice is the best way to build confidence.
Launch a full Strings practice session with instant scoring and detailed explanations.
Start Strings Practice →