Module (36%)
Section (36%)

We should get familiar with some special attributes:

  • __name__ – inherent for classes; contains the name of the class;
  • __class__ – inherent for both classes and instances; contains information about the class to which a class instance belongs;
  • __bases__ – inherent for classes; it’s a tuple and contains information about the base classes of a class;
  • __dict__ – inherent for both classes and instances; contains a dictionary (or other type mapping object) of the object's attributes.

The output of the code presented in the right pane:

"dog" is an object of class named: Dog class "Dog" is an instance of: <class 'type'> instance "dog" is an instance of: <class '__main__.Dog'> class "Dog" is (<class 'object'>,) class "Dog" attributes: {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Dog' objects>, '__weakref__': <attribute '__weakref__' of 'Dog' objects>, '__doc__': None} object "dog" attributes: {}

output


Code

class Dog:
pass

dog = Dog()
print('"dog" is an object of class named:', Dog.__name__)
print()
print('class "Dog" is an instance of:', Dog.__class__)
print('instance "dog" is an instance of:', dog.__class__)
print()
print('class "Dog" is ', Dog.__bases__)
print()
print('class "Dog" attributes:', Dog.__dict__)
print('object "dog" attributes:', dog.__dict__)
{{ dockerServerErrorMsg }} ×
{{ errorMsg }} ×
{{ successMsg }} ×