PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
Given the tuple t = (1, 2, 3, 4, 5), which expression returns the last element?
⚠ Common exam trap
A common trap in PCEP exams is that candidates may use a hardcoded index like t[4] which works for this specific tuple but fails if the tuple length changes. The correct dynamic way is t[-1], which always references the last element regardless of tuple length.
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
✓
t[-1]
In Python, negative indices count from the end of a sequence. For the tuple t = (1, 2, 3, 4, 5), t[-1] accesses the last element (5), because -1 refers to the final position. This is a standard feature of Python's sequence indexing.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
t[-1]
Why this is correct
Negative indexing counts from the end, so t[-1] returns the final element, 5. This directly satisfies the stem's requirement for the last element, whereas t[0] gives the first and t[5] raises an IndexError because indices stop at 4.
- ✗
t[5]
Why it's wrong here
Tuple indices start at 0, so t[5] exceeds the valid range 0 to 4 and raises an IndexError; the last element is t[-1] or t[4]. It is tempting because 5 matches the tuple's length, a natural but incorrect assumption for one-based access.
- ✗
t[4]
Why it's wrong here
Index 4 returns the fifth element, which happens to be the last only because this tuple has exactly five items. The stem asks for a general last-element expression; t[-1] works regardless of length, whereas t[4] breaks on any other tuple.
- ✗
t[0]
Why it's wrong here
Index 0 addresses the first element, returning 1, not the last. Negative indexing or t[4] reaches the final item. Beginners often assume Python counts from one, but zero-based indexing means t[0] is always the head of the sequence.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.