The following code was more unpredictable than I had expected.
Test case 1:
# Line with print is OK:
y4 = 0
def G6():
print(f"y4={y4}")
G6()
Output: y4=0
Test case 2:
# Line with print throws error this time:
# UnboundLocalError: local variable 'y5' referenced before assignment
# But why exactly? If y5 is a local variable, then y4 (above) should be too, IMO.
# Is y4 (above) even a local variable? Is y4 (above) also being referenced before assignment, or not?
y5 = 0
def G7():
print(f"y5={y5}")
y5 += 2
G7()
Output on the line print(): UnboundLocalError: local variable 'y5' referenced before assignment
Can this python behavior be rationalized?