Question 1
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
word = "python"
print("Last letter:", word[len(word)])
- A TypeError: len() returns a str
- B IndexError: valid indexes are 0 to len(word) - 1; use word[-1] or word[len(word) - 1] Correct
- C It prints Last letter: n
- D SyntaxError: nested brackets
Correct Answer: Option B
A 6-character string has indexes 0–5. word[-1] is the idiomatic last character.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!