I am learning Python scope and unable to understand with a program, here is my code
a = "bat"
class Test():
a = "ball"
b = [a for i in range(2)]
e = lambda: a
@staticmethod
def f():
return a
g = lambda a=a: a
d = a
print(Test.b) # prints ["bat","bat"]
print(Test.e()) # prints bat
print(Test.f()) # prints bat
print(Test.g()) # prints ball
print(Test.d) # prints ball
Here I have declared variable a="bat" outside the class and then I declared variable a="ball" inside class which is local to it. When I access the local a="ball" inside the class how is it returning the variable a="bat" declared outside the class in first 3 prints & not in the last 2 prints?