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
  • 14,486
  • 4
  • 43
  • 54
fardV
  • 135
  • 8

1 Answers1

3

From the documentation:

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

chepner
  • 446,329
  • 63
  • 468
  • 610