For nums = [10, 20, 30, 40], what is nums[-1]?
-
A
10
-
B
An IndexError
-
C
40
Correct answer
-
D
30
16 views
Explanation
Negative indexing counts from the end: −1 is the last item and −2 the second-last. It works on strings and tuples too.
Reference
Asked in: NTS, PPSC, Python Developer Interviews
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ