Answer: Python Puzzler #1693

The answer is C. The program prints:

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

Why?

word[2:4] is a slice: it starts at position 2 and stops before position 4. Positions count from 0.

Trace table

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

positionletter
0P
1Y
2T
3H
4O
5N

The code again

word = "PYTHON"
print(word[2:4])

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