+1 vote
in Class 12 by kratos

What do you mean by globals() and locals () Functions

1 Answer

+3 votes
by kratos
 
Best answer

The globals( ) and locals( ) functions can be used to return-the names in the global and local namespaces depending on the location from where they are called. If locals() is called from within a function, it will return all the names that can be accessed locally from that function.

If globals() is called from within a function, it will return all the names that can be accessed globally from that function .The return type of both these functions is dictionary. Therefore, names can be extracted using the keys() function

...