What is local scope?
What is local scope?
a. From the moment we start the program in Python, we are in the local scope. Python turns the main script into a module called __main__
that stores the execution of the main program. The namespace of this module is the local scope of the program.
b. Local scope is created when the function is called. Each time we call the function we create a new local scope. By default, variables inside functions only exist in the local scope associated with the function call. When the function exits, the local scope is destroyed.
c. Global scope only appears when you nest functions within other functions.
1 Answers