What do you mean by globals() and locals () functions.

 

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 the locals( ) function is called from within a function, it will return the names of all the variables that can be accessed locally from that function.

If the globals( ) function is called from within a function , it will return the names of all the variables that can be accessed globally from that function.  

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo