Fonction vars() – Python
La fonction vars() renvoie l’attribut __dic__ d’un objet. L’attribut __dict__ est un dictionnaire contenant les attributs modifiables de l’objet.
Syntaxe:
vars(object)
Paramètres:
La méthode vars() prend un seul paramètre:
- object : Tout objet avec un attribut __dict__
Exemple:
Le code suivant renvoie l’attribut __dict__ de l’objet Person:
class Person: name = "Alex" age = 18 address = "Paris" v = vars(Person) print(v)
Sortie:
{
'__dict__': <attribute '__dict__' of 'Person' objects>,
'__doc__': None,
'__weakref__': <attribute '__weakref__' of 'Person' objects>,
'address': 'Paris',
'name': 'Alex', 'age': 18,
'__module__': '__main__'
}





