Here's something that surprised me:
a = None
def f():
b = a
return b
def g():
b = a
a = 'foo'
return b
While f() is perfectly fine, g() raises an UnboundLocalError. This is because Python optimises access to local variables using the LOAD_FAST/STORE_FAST opcode, you can easily see why this …