__dict__

The dictionary that holds an object's own attributes, or a class's own attributes.

In more detail

An object's __dict__ holds only its instance variables, the names assigned through self or through the object. A class's __dict__ holds its class variables and methods. Reading obj.name looks in the object's __dict__ first and then in its class, which is why a class variable can be read through an object without appearing in the object's __dict__.

Example

class T:
    price = 10
    def __init__(self):
        self.seat = 'A1'

print(T().__dict__)   # {'seat': 'A1'}

Related terms

Taught in

References

Certification courses