Using not defined variable in function body
<p>There is this code:</p>

<pre><code>def f():
  x = m 
  m = 2 

def g():
  x = m

f() # UnboundLocalError: local variable 'm' referenced before assignment
g() # NameError: global name 'm' is not defined
</code></pre>

<p>In both function bodies there is used variable <code>m</code> which is not defined when used but the error messages are different. Do Python know what variables are defined in function before using them (like in function <code>f</code>)? Why the error messages are different?</p>
