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

Python vars() Function

Python vars() Function

Python built-in function Python built-in function


Description

vars() The function returns a dictionary object of an object's attribute names and values.

Syntax

vars() function syntax:


vars([object])

Parameters

Return Value

Returns a dictionary of an object's attribute names and values. If no argument is given, it prints the attributes and values at the current call location, similar to locals().

Example

The following examples demonstrate how to use vars():

print

(

vars

(

)

)

{

'

builtins

'

: <

module

'

builtin

'

(

built

in

)

,

'

name

'

:

'

main

'

,

'

doc

'

:

None

,

'

package

'

:

None

} >>>

class

Runoob

: ...

a

=

1

... >>>

print

(

vars

(

Runoob

)

)

{

'

a

'

:

1

,

'

module

'

:

'

main

'

,

'

doc

'

:

None

} >>>

runoob

=

Runoob

(

)

print

(

vars

(

runoob

)

)

{}

Python built-in function Python built-in function