Python locals() Function
Description
locals() The function returns all local variables at the current location as a dictionary.
For functions, methods, lambda functions, classes, and those that implement call method, it returns True.
Syntax
locals() function syntax:
locals()
Parameters
- None
Return Value
Returns local variables as a dictionary.
Example
The following examples demonstrate how to use locals():
def
runoob
(
arg
)
:
Two local variables: arg, z
...
z
=
1
...
(
locals
(
)
)
... >>>
runoob
(
4
)
{
'
z
'
:
1
,
'
arg
'
:
4
}
Python built-in function