Python 101 : Special functions and attributes - __dict__, __dir__, __doc__, ... -


 We have for example a class named "a" with no defined functions:


The dir() function prints the methods and attributes - inherited from the object parent class -.

Below is a short description of some of them:
__gt__  : is called for testing if an object is greater
We have a "Car" class and we will use the __dict__ and __doc__ attributes to dispaly both the docstrings and the attributes of the class "Car": 


We can add other attributes like the "price" for example as below:

Comments

Leave as a comment:

Archive