Function within a function in python
<p>I recently came across this idea of defining a function within a function in Python. I have this code and it gives error: </p>

<hr>

<pre><code>def f1(a):
    def f2(x):
       return a+x
    return 2*a
</code></pre>

<hr>

<p>Error: On calling <code>f2(5)</code></p>

<pre><code>Traceback (most recent call last):
File "&lt;pyshell#19&gt;", line 1, in &lt;module&gt;
f2(5)
NameError: name 'f2' is not defined
</code></pre>

<hr>

<p>I have some difficulty understanding the way global variables are used across functions or even in recursive calls. I would really appreciate if someone would point out my mistake and may be help me along the way. Thanks in advance !!</p>
