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 APItest is given along with various nested functions defined within it Defining distinct namespaces in a single code, locally or nonlocally, can alter the binding of other functions when the global function is called. Which function would be bound to the last print statement?
def APItest:
def dolocal:
API "local API"
def dononlocal:
nonlocal API
API "nonlocal API"
def doglobal:
global API
API "global API"
API "test API"
dolocal
printAfter local assignment:", API
dononlocal
printAfter nonlocal assignment:", API
doglobal
printAfter global assignment:", API
scopetest
printIn global scope:", API
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
