Jun-24-2024, 01:42 PM
global is only used inside functions. The purpose of global is to tell python that the variable(s) is in the global scope, and assignment to the variable should not create a local variable inside the function. The code where you use "once" is not inside a function. Any variables assigned in the while loop are global.
Interestingly, this is a syntax error:
Interestingly, this is a syntax error:
once = 0 while True: global once if once == 0:But this is not. It raises a NameError when run, but it is not a syntax error.
while True: global once if once == 0: