Python vars() Function
Description
vars() The function returns a dictionary object of an object's attribute names and values.
Syntax
vars() function syntax:
vars([object])
Parameters
- object -- the object
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():
(
vars
(
)
)
{
'
builtins
'
: <
module
'
builtin
'
(
built
in
)
,
'
name
'
:
'
main
'
,
'
doc
'
:
None
,
'
package
'
:
None
} >>>
class
Runoob
: ...
a
=
1
... >>>
(
vars
(
Runoob
)
)
{
'
a
'
:
1
,
'
module
'
:
'
main
'
,
'
doc
'
:
None
} >>>
runoob
=
Runoob
(
)
(
vars
(
runoob
)
)
{}
Python built-in function