Electron microscopy
 
PythonML
locals()
- Python Automation and Machine Learning for ICs -
- An Online Book -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

The locals() function in Python returns a dictionary containing the variables defined in the current local namespace.  

============================================

When we run this script below, it defines a function my_function() which assigns values to variables x and y. Inside the function, it calls locals() to get a dictionary containing all local variables within the function. Finally, it prints out the local variables and their types. Code

   Output:

============================================

When we run this script below, it will output the local variables defined within the my_locals() function along with their values. Code

   Output:

============================================

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================