Given the tuple t = (1, 2, 3, 4, 5), which expression returns the last element?
Negative index -1 refers to the last element.
Why this answer
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.
Exam trap
Python Institute often tests the distinction between zero-based indexing and negative indexing, trapping candidates who mistakenly think t[5] or t[4] is the correct way to access the last element without considering index out-of-range or dynamic length scenarios.
How to eliminate wrong answers
Option B is wrong because t[5] attempts to access index 5, which is out of range for a tuple with indices 0 through 4, raising an IndexError. Option C is wrong because t[4] returns the element at index 4, which is 5, but this is the last element only coincidentally; the question asks for an expression that returns the last element in general, and t[4] is not a robust way to do it if the tuple length changes. Option D is wrong because t[0] returns the first element (1), not the last.