Python | Namespace
Автор: Florence Sharmila
Загружено: 2020-03-21
Просмотров: 85
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)
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: