0
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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
fardV
  • 198
  • 9

1 Answers1

4

From the documentation:

Note that at the module level, locals() and globals() are the same dictionary.

chepner
  • 497,756
  • 71
  • 530
  • 681