Defines when the variable is available for use.
Example:
def f(l):
...
for x in l:
y = y+ g(x)
...
def g(m):
...
for x in range(m): # the x here is not same as x in the function f()
...
...
In the above codes, the variable x
in f()
is NOT in scope within the call to g()
x
is only till f()
exits.<aside> 💡 Hole in Scope → Variable is alive but not in scope.
</aside>
factorial(3)
factorial(3)
calls factorial(2)
factorial(2)
)are in scope.Memory with 2 activation records.