Hey guys I was referring to an article on decorators and to explain python closures the author used an example like this.
def outer():
def inner():
print("Inside inner")
return inner
foo = outer()
foo() # prints "Inside inner"
The part which is confusing to me is foo is not explicitly a function but a variable. We use paranthesis just to call a funciton.
Calling variable foo as foo() should give an error saying no such function exists according to my understanding of functions.
outer()is a function. That's why it's callable.foois just a name for an object like any other name.inneris a name for a function.outerandinnerare variables, too - ones whose initial value is a function. In Python,defis really just a very specialized form of assignment statement.