Python: Why is global needed only on assignment and not on reads?
问题 If a function needs to modify a variable declared in global scope, it need to use the global declaration. However, if the function just needs to read a global variable it can do so without using a global declaration: X = 10 def foo(): global X X = 20 # Needs global declaration def bar(): print( X ) # Does not need global My question is about the design of Python: why is Python designed to allow the read of global variables without using the global declaration? That is, why only force