+ 1
Python, globals and locals
Why first output is False, and second True? def foo(): print(globals()==locals()) foo() print(globals()==locals())
1 ответ
+ 2
locals() returns you a dictionary of variables declared in the local scope while globals() returns you a dictionary of variables declared in the global scope. At global scope, both locals() and globals() return the same dictionary to global namespace.
Try by printing locals() and globals() inside and outside the function.