y=3
class A:
x = 1
print(locals())
print()
print(globals())
print(globals())
print()
print(locals())
Why does the last line for locals()
include the variable y
even if it is global?
y=3
class A:
x = 1
print(locals())
print()
print(globals())
print(globals())
print()
print(locals())
Why does the last line for locals()
include the variable y
even if it is global?
From the documentation:
Note that at the module level,
locals()
andglobals()
are the same dictionary.