locals()Easy Examples

Returns a dictionary of the current local symbol table

Basic locals() usage

Simple demonstration of the locals() built-in function.

python
def example():
    a = 1
    b = 2
    print(locals())

example()

locals() is a built-in function that returns a dictionary of the current local symbol table.

locals() with different inputs

Calling locals() with various argument types.

python
# More locals() examples
print("locals() is a Python built-in function")
print(f"Type: {type(locals)}")

locals() accepts different types of arguments and produces corresponding results.

Want to try these examples interactively?

Open Easy Playground