Python locals() Function

Returns a dictionary of the current local symbol table. The local symbol table are the variables that are in the "scope" of the current block and any parent block of  function.

Syntax

Python
locals()

Example

Python
def myFunction():
    n = 0
    print(locals())

myFunction()

def anotherFunction():
    n = 0

    if (n == 0):
        q = 1
        print(locals())

anotherFunction()

Output

{'n': 0}
{'n': 0, 'q': 1}