PCEP Control Flow, Loops, Lists and Logic Practice Question
A list of numbers is defined as nums = [1, 2, 3, 4, 5]. Which expression returns the last element?
⚠ Common exam trap
The trap here is that candidates often forget Python's zero-based indexing and mistakenly think the last element is at index equal to the list length (e.g., nums[5]), or they confuse negative indexing and pick nums[-2] thinking it refers to the last element.
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
✓
nums[-1]
Python uses zero-based indexing, so the first element is at index 0 and the last element is at index -1. Negative indices count from the end of the list, so nums[-1] directly accesses the last element (5) without needing to know the list length.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
nums[5]
Why it's wrong here
Index out of range.
- ✓
nums[-1]
Why this is correct
Correct negative indexing.
- ✗
nums[0]
Why it's wrong here
Returns first element.
- ✗
nums[-2]
Why it's wrong here
Returns second-to-last.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-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.