Python | Namespace

Опубликовано: 21 Март 2020
на канале: 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)


На этой странице сайта вы можете посмотреть видео онлайн Python | Namespace длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Florence Sharmila 21 Март 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 85 раз и оно понравилось 2 зрителям. Приятного просмотра!