Python locals() Function

Example

Display the local symbol table:

x = locals()
print(x)

Run Instance

Definition and Usage

The locals() function returns the local symbol table as a dictionary.

The symbol table contains necessary information about the current program.

Syntax

locals()

Parameter Value

No Parameters

More Examples

Example

Get the filename of the current program:

x = locals()
print(x["__file__"])

Run Instance