CASE1:def local():l=55print('inside local',l)l+=5local()OUTPUT:inside local 55
local var l accessed and Modified in Function local().
CASE2:
def local():
l=55
print('inside local',l)
l+=5
local()
print('outside access of local',l)
OUTPUT:
ERROR:
print('outside access of local',l)
NameError: name 'l' is not defined
"Local Var l is not accessing outside function ,because its life are only inside function local()
CASE-3
def local():
global l
l=55
print('inside local',l)
l+=5
local()
print('outside access of local',l)
OUTPUT
inside local 55
outside access of local 60
local var l inside local() function can be accessed outside function ,when declared as global .global l
No comments:
Post a Comment