Closure Inspection

Take a look inside a closure to find out about its free variables and their values.

We'll cover the following...

Inside a closure

You can look inside a closure to learn the values of its variables. Here is an example of a closure:

Press + to interact
def f(x, a, v):
def g(e):
print(x, a, v, e)
return g
c = f(5, 6, 7)
c(2)

Python provides methods to inspect an object more deeply. On line 7 in the code above, the function, f, returns the function ...

Access this course and 1400+ top-rated courses and projects.