Python locals() function

Published February 16, 2022

The locals() function is a built-in  Python function that is used to update and return the  dictionary of the current local symbol table.  In python, a symbol table refers to a data structure containing all the important information concerning the program. This information can include methods, names, classes, etc.
Let's look at the syntax of the locals() function

Syntax
This built-in Python function does not  take any  input  parameter

Locals()

Example

Let's look at the example below

def localsPython():
    Python = True
    print(Python)
    locals()['python'] = False;
    print(Python)
localsPython()

 

Output

True
True

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

167 Views