Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python locals() Function

Python locals() Function

Python built-in function Python built-in 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

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

...

print

(

locals

(

)

)

... >>>

runoob

(

4

)

{

'

z

'

:

1

,

'

arg

'

:

4

}

Returns a dictionary of name/value pairs

Python built-in function Python built-in function