Python | Namespace

Veröffentlicht am: 21 März 2020
auf dem Kanal: Florence Sharmila
85
2

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)


Auf dieser Seite können Sie das Online-Video Python | Namespace mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Florence Sharmila 21 März 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 85 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!