I was messing around with the scoping in python and found something that I think is rather strange:
g = 5
def foo(a):
if a:
global g
g = 10
else:
g = 20
print("global g: ",g)
foo(False)
print("global g: ",g) # 20?! What?
foo(True)
print("global g: ",g)
My believe was that the second print should have been "5" since the global statement was never executed, but clearly, the output is 20(!).
What's the logic behind this?