A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-39.py
1deff():
2print(str)
3str="x"
4try:
5f()
6exceptUnboundLocalErrorase:
7print(type(e).__name__)
Scope
Answer & explanation
Console output
UnboundLocalError
Why
Because str is assigned somewhere in f, Python treats str as a local for the entire function, which shadows the builtin str. The print(str) then references that local before its assignment runs, raising UnboundLocalError rather than showing the builtin. Local-versus-builtin is decided at compile time for the whole function body.