PCEP Computer Programming and Python Fundamentals Practice Question
Given the code: my_list = [1, 2, 3, 4, 5]. What is the output of print(my_list[-3:-1])?
⚠ Common exam trap
The trap here is that candidates often forget that the end index in a slice is exclusive, causing them to include the element at index -1 and choose option D instead of B.
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
✓
[3, 4]
Python list slicing with negative indices counts from the end of the list. my_list[-3:-1] starts at index -3 (value 3) and goes up to but does not include index -1 (value 5), so it returns [3, 4].
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
[4, 5]
Why it's wrong here
Negative slicing stops before the end index, so -1 excludes the final element; [4, 5] would require the slice [-2:]. It tempts because -1 is often mistaken for the last inclusive position, but Python slice end bounds are always exclusive.
- ✓
[3, 4]
Why this is correct
Negative indices count from the end, so -3 maps to index 2 (value 3) and -1 maps to index 4 (value 5). Slicing excludes the stop index, returning elements at positions 2 and 3, giving [3, 4].
- ✗
[2, 3]
Why it's wrong here
Starting at -3 selects index 2, not index 1, so the slice begins at 3; [2, 3] would require [-4:-2]. It tempts because counting backwards from the list's end is easily off by one, but negative indices map directly onto positions from the right.
- ✗
[3, 4, 5]
Why it's wrong here
The end index -1 is exclusive, so element 5 is never included; [3, 4, 5] would need an omitted stop or [:]. It tempts because -1 intuitively reads as the last element, yet slicing always stops one position before the specified end.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-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 PCEP 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 PCEP exam.