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 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: Both B and C match four octets of 1–3 digits separated by periods and will correctly extract IPs from a string. Option A contains an erroneous space, and option D allows octets of any length. Since the question asks for a pattern that correctly extracts, both B and C are valid; a single correct answer cannot be justified.
Given the string s = 'Hello World!', which expression returns a list of characters?
Explanation: The `list()` constructor, when passed a string, iterates over each character in the string and returns a list where each element is a single character. For `s = 'Hello World!'`, `list(s)` produces `['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!']`, which is exactly a list of characters.
Which of the following is the correct way to format a string with variables?
Explanation: Option C uses an f-string (formatted string literal), the modern recommended way in Python 3.6+ to embed variables directly into strings. Option A uses old-style % formatting, which is syntactically correct but outdated and less readable, so it is not the best modern approach. Option B is incorrect because .format() with named placeholders like {name} requires keyword arguments (e.g., .format(name=name, age=age)); passing positional arguments without indices will raise a KeyError. Option D is incorrect because it swaps the positional indices, so it would put age in place of name and vice versa.
Which of the following methods can be used to check if a string starts with a vowel?
Explanation: The `str.startswith()` method accepts a tuple of prefixes to check against. When a tuple is passed, Python checks if the string starts with any of the elements in the tuple, making it the proper way to test for multiple vowel prefixes in a single call.
Given s = 'Hello\nWorld!\n\n\n\n\n\n', what is the length of string s?
Explanation: The string s = 'Hello\nWorld!\n\n\n\n\n\n' contains 7 newline escape sequences: one after 'Hello' and six after 'World!'. Each \n is a single character. Counting: H(1), e(2), l(3), l(4), o(5), \n(6), W(7), o(8), r(9), l(10), d(11), !(12), then the six additional newlines (13-18). Total length = 18. A common mistake is to miscount the newline escapes or to treat \n as two characters; if you treated all 7 \n as two characters, the length would be 25, not 19.
+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 →