A namespace is a system to have a unique name for each and every object in Python. An object might be a variable or a method.
LEGB rule : In Python, the LEGB rule is used to decide the order in which the namespaces are to be searched for scope resolution.
Local(L): Defined inside function/class
Enclosed(E): Defined inside enclosing functions(Nested function concept)
Global(G): Defined at the uppermost level
Built-in(B): Reserved names in Python builtin modules
Case 1: Output: 12 25
def calsum(x,y):
z=x+y
print(a)
return z
a=int(input("Enter the first no.")) # input= 12
b=int(input("Enter the second no.")) # input= 13
sum=calsum(a,b)
print("result", sum)
Case 2: Output: 95 15 95
def case2():
global carona
carona=15
print(carona)
carona= 95
print(carona)
case2()
print(carona)
Case 3: Output: 95 15 15
def case2():
global carona
carona=15
print(carona)
carona= 95
print(carona)
case2()
print(carona)
On this page of the site you can watch the video online Python | Namespace with a duration of hours minute second in good quality, which was uploaded by the user Florence Sharmila 21 March 2020, share the link with friends and acquaintances, this video has already been watched 85 times on youtube and it was liked by 2 viewers. Enjoy your viewing!