Answer: Python Puzzler #1427

The answer is D. The program prints:

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

Why?

word[1:4] is a slice: it starts at position 1 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
0T
1U
2R
3T
4L
5E

The code again

word = "TURTLE"
print(word[1:4])

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