locals()
Anonymous contributor
Published Oct 4, 2024
Contribute to Docs
The locals()
built-in function in Python returns a dictionary containing the current local symbol table, which maps variable names to their values in the current scope.
Syntax
locals()
Example
The following example demonstrates the usage of the locals()
function:
def example1():print( "No local variables." , locals() )def example2():ex= "A"print( "One local variable." , locals() )example1()example2()
The code above generates the following output:
No local variables. {}One local variable. {'ex': 'A'}
Note:
locals()
cannot change the local symbol table. It only allows seeing it.
Codebyte Example
Run the following code to understand how the locals()
function works:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.