practicepython.in
python exercises
171 exercises

Daily #32 · 30 October 2026

Finding nothing Hard

What does this print?

s = "hello"
i = s.find("z")
print(s[i])
  1. Araises IndexError
  2. Bo
  3. Craises ValueError
  4. Dh
Show the answer

B: o

Why: find returns -1 when the text is not there, and -1 is a valid index: the last character. No error is raised. Check if i != -1 first, or use index, which raises ValueError instead.

Play today’s puzzle →