title: Python 3 variable scoping (2 test cases): Is y4 a local variable? Is y4 being referenced before assignment?
body: <p>The following code was more unpredictable than I had expected.</p>
  
  <p>Test case 1:</p>
  
  <pre><code># Line with print is OK:
  
  y4 = 0    
  
  def G6():
      print(f"y4={y4}")
  
  G6()
  </code></pre>
  
  <p>Output:
  y4=0</p>
  
  <p>Test case 2:</p>
  
  <pre><code># 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()
  </code></pre>
  
  <p>Output on the line print():
  UnboundLocalError: local variable 'y5' referenced before assignment</p>
  
  <p>Can this python behavior be rationalized?</p>