Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is vars() same as __dict__?

Tags:

python

I read that vars() is a built-in that returns the __dict__ attribute of class, module or object. But when I checked for vars(Person) is Person.__dict__, it returned False(Person is the name of class).

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

vars(Person) is Person.__dict__  # False
like image 916
Anunad Singh Avatar asked Sep 06 '25 03:09

Anunad Singh


1 Answers

Classes create a new mappingproxy on every __dict__ access. You would see the exact same results from Person.__dict__ is Person.__dict__.

like image 169
user2357112 supports Monica Avatar answered Sep 07 '25 15:09

user2357112 supports Monica