I recently came across the idea of defining a function within a function in Python. I have this code and it gives this error:
def f1(a):
def f2(x):
return a+x
return 2*a
Error: On calling f2(5)
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
f2(5)
NameError: name 'f2' is not defined
I am having some difficulty understanding the way global variables are used across functions or even in recursive calls. I would really appreciate it if someone would point out my mistake and maybe help me along the way. Thanks!!