PCAP Strings Practice Question
Given s = 'a1b2c3', which TWO of the following expressions return the string '123'?
⚠ Common exam trap
Python Institute often tests the misconception that slicing with a step of 2 always starts from index 0, causing candidates to overlook the correct starting index needed to isolate digits from a mixed string.
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
✓
s[1::2]
Slicing with `s[1::2]` starts at index 1 (the character '1'), goes to the end of the string, and takes every second character, resulting in '1', '2', '3' concatenated as '123'. Option C is also correct because `s[1:6:2]` starts at index 1, stops before index 6 (the string length is 6, so index 6 is just past the last character), and steps by 2, yielding the same sequence of 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.
- ✗
s[0:5:2]
Why it's wrong here
s[0:5:2] uses a step of 2 starting at index 0 and stopping before index 5, so it selects indices 0, 2, and 4. This yields the characters 'a', 'b', and '2', producing the string 'ab2' rather than only the digits. Because the first element is a letter, this slice does not match the target substring '123'.
- ✓
s[1::2]
Why this is correct
s[1::2] begins at index 1 (the first digit character '1') and then takes every second character thereafter, with no explicit stop so it runs to the end of the string. Indices 1, 3, and 5 correspond to '1', '2', and '3', respectively, so the result is exactly '123'. This is the correct expression because it isolates the digits that are positioned at odd indices.
- ✓
s[1:6:2]
Why this is correct
s[1:6:2] is equivalent to s[1::2] for this string because the explicit stop index of 6 is the length of s, so slicing stops at the end anyway. With start at 1 and step 2, it collects indices 1, 3, and 5, yielding '1', '2', and '3'. Although it correctly produces '123', it is not the only correct expression—it merely spells out the default stop value.
- ✗
s[0::2]
Why it's wrong here
s[0::2] starts at index 0 with a step of 2 and continues to the end, so it takes indices 0, 2, and 4. Those positions hold the letters 'a', 'b', and 'c', making the result 'abc'. This fails because the step pattern from index 0 lands only on the letter characters, not the digits.
- ✗
s[2:5:1]
Why it's wrong here
s[2:5:1] uses a step of 1, meaning it is a contiguous slice from index 2 through index 4. The characters are 'b', '2', and 'c', producing 'b2c'. While it does contain the middle digit, it includes surrounding letters and skips the first and last digits, so it is not the desired '123'.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 169-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.