Hacker News new | ask | show | jobs
by sandov 2418 days ago
> Most programmers are surprised by the behavior of this snippet.

Ok. I'll bite.

I get UnboundLocalError: local variable 'a' referenced before assignment

shouldn't it print 0 twice, since a is considered a global variable at the time print(a) gets called?

EDIT: If I delete print(a), then it prints 0 twice. What the hell?