Question: In the following code, a global function, def API _ test ( ) , is given along with various nested functions defined within it .

In the following code, a global function, def API_test(), is given along with various nested functions defined within it. Defining distinct namespaces in a single code, locally or non-locally, can alter the binding of other functions when the global function is called. Which function would be bound to the last print statement?
def API_test():
def do_local():
API1= "local API"
def do_nonlocal():
nonlocal API
API1= "nonlocal API"
def do_global():
global API
API1= "global API"
API1= "test API"
do_local()
print("After local assignment:", API1)
do_nonlocal()
print("After nonlocal assignment:", API1)
do_global()
print("After global assignment:", API1)
scope_test()
print("In global scope:", API1)
In the following code, a global function, def API

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!