Home » locals() in Python | Python locals() Function with Examples

locals() in Python | Python locals() Function with Examples

by Online Tutorials Library

Python locals() Function

The python locals() method updates and returns the dictionary of the current local symbol table.

A Symbol table is defined as a data structure which contains all the necessary information about the program. It includes variable names, methods, classes etc.

Signature

Parameters

It does not contain any parameters.

Return

It returns the dictionary of the current local symbol table.

Python locals() Function Example 1

The below example shows the working of locals() inside a local scope.

Output:

localsAbsent: {}  localsPresent: {'present': True}  

Explanation: The above example updates and returns the dictionary of the current local symbol table.

Python locals() Function Example 2

The below example shows how to update locals() dictionary values.

Output:

True  True  

Next TopicPython Functions

You may also like