Warum kann ich in Python keine globale Variable festlegen?
Wie funktionieren globale Variablen in Python? Ich weiß, dass globale Variablen böse sind, ich experimentiere nur.
Dies funktioniert nicht in Python:
G = None
def foo():
if G is None:
G = 1
foo()
Ich erhalte einen Fehler:
UnboundLocalError: local variable 'G' referenced before assignment
Was mache ich falsch?