Inner Functions, Scope, and the LEGB Rule
Learn about the scope of inner functions and the LEGB rule in Python.
We'll cover the following...
Inner functions
An inner function is simply a function that is defined inside another function. The following program shows how to do this:
Press + to interact
# outer functiondef display( ) :a = 500print ('Saving is the best thing...')# inner functiondef show( ) :print ('Especially when your parents have done it for you!')print(a)show( )display( )
In the code above, show()
is the inner function defined inside display()
. Therefore, it can only be called from within display()
. In that ...