Special attributes#
This is an attribute of the class that usually has a purpose associated with the ideas behind the programming language. In fact, every object in python has some special methods but they can come from different sources. This page looks at special attributes from different sources.
Type attributes#
Class can be thought of as defined your own instance of the type
, so each instance of type
contains a set of default attributes. The complete list is described in the corresponding section of the documentation.
As an example we’ll take int
type. But any class in particular custom class will follow the same rules.
The __name__
attribute retains the name of the type. The following code shows the case where you gave another reference to your class, but __name__
attribute still keeps information about original name of the object.
wow = int
wow.__name__
'int'
The __mro__
attribute contains information about inheritance order of the class.
int.__mro__
(int, object)
Instance attributes#
There is a list of attributes of which each defined instance checks both read-only and writable attributes on the relevant internet page.
The following cell defines class and object we’ll use as the example.
class MyClass:
val: int
wow: float
my_object = MyClass()
__dict__
holds all attributes of the object as keys and corresponding values.
my_object.a = "test"
my_object.__dict__
{'a': 'test'}
The __class__
attribute holds the name of the class from which the instance was created.
my_object.__class__
__main__.MyClass