Can a variable be used inside a function without a Global declaration inside that function
<p>CODE 1:</p>

<pre><code>x=4    
def func():
          print("HELLO WORLD")
          y=x+2
          print (y)
          print (x) # gives o/p as HELLO WORLD 6,4,4.

func()    
print (x)
</code></pre>

<p>CODE 2:</p>

<pre><code>x=4    
def func():

          print("HELLO WORLD")
          y=x+2
          x=x+2 # gives an error here
          print (y)
          print (x) 

func()
print (x)
</code></pre>

<p>In the first code, it is not showing any error, it's adding the <code>x</code> value to 2 and resulting back to <code>y</code> and it prints the o/p as <code>6,4,4</code>. But Actually as I learnt so for, it should point an error because I am not giving the global declaration for <code>x</code> variable inside the <code>func()</code>. But its not ponting any error but in <code>Code 2</code> it gives an error saying that <code>x referenced before assignment</code>.</p>

<p>The question is can <code>x</code> can be used for the assignment of its value to other variables? Even it is not followed with global declaration?</p>
