Answer: Python Puzzler #760

The answer is C. The program prints:

banana
What the program prints
Checked by running the program for real.

Why?

Python counts list positions from 0, so position 5 is the sixth item.

Trace table

A trace table follows the program step by step. Here’s this one:

positionnegative positionitem
0-6grape
1-5melon
2-4apple
3-3mango
4-2carrot
5-1banana

The code again

basket = ["grape", "melon", "apple", "mango", "carrot", "banana"]
print(basket[5])

Try it: change one number in the program and predict the new output before you run it.