PCAP Strings Practice Question
Given s = 'Python', what is s[1:4]?
⚠ Common exam trap
Python Institute often tests the half-open interval behavior of slicing, where candidates mistakenly include the character at the stop index (e.g., choosing 'ytho' by including index 4) or confuse zero-based indexing with one-based indexing (e.g., choosing 'pyt' or 'Pyt' by starting at index 0).
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
✓
'yth'
In Python, string slicing with `s[start:stop]` extracts characters from index `start` up to but not including index `stop`. Since indexing starts at 0, `s[1:4]` on 'Python' takes indices 1 ('y'), 2 ('t'), and 3 ('h'), resulting in 'yth'. Option B is correct because it exactly matches this slice.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
'pyt'
Why it's wrong here
'pyt' is not a valid slice of s = 'Python' from s[1:4] because slicing preserves the original casing of the characters. The lowercase 'p' would have to come from the first character 'P' (index 0), but a slice starting at index 1 skips index 0 entirely; indices 1, 2, and 3 are 'y', 't', and 'h'. The string 'pyt' would only appear if someone manually lowercased the first three characters, which is a transformation that s[1:4] does not perform.
- ✓
'yth'
Why this is correct
For s = 'Python', s[1:4] returns 'yth' because Python string indices are zero-based and slice end points are exclusive. The characters are P(0), y(1), t(2), h(3), o(4), n(5), so the slice takes positions 1, 2, and 3. Those positions spell 'y', 't', 'h' in order, giving exactly 'yth', which is the correct answer.
- ✗
'ytho'
Why it's wrong here
'ytho' is the result of s[1:5], not s[1:4], because it incorrectly includes the 'o' at index 4. Python's slice notation [start:end] never includes the character at the end index, so an end index of 4 stops before 'o'. Thus 'ytho' is one character too long and would require extending the slice to s[1:5].
- ✗
'Pyt'
Why it's wrong here
'Pyt' would be produced by s[0:3], since it starts with the uppercase 'P' found at index 0. The given slice s[1:4] begins at index 1 (the 'y') and therefore cannot include the initial 'P'. Including that capital letter would require a start index of 0, not 1, so 'Pyt' does not match s[1:4].
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-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.