A class is a combination of similar characteristics and skills of a series of objects. For the same thing, the classes obtained from different angles are different.
The relationship between objects and classes
In the real world, there must be objects first and then classes; but in the program, it is just the opposite. Classes must be defined first, and then classes are called to generate objects.
#First define the class class LuffyStudent: school = 'luffycity' def learn(self): print('is learning') def eat(self): print('is eating') def sleep(self): print('is sleeping') #After the object is generated stu1 = LuffyStudent() #Instead of executing the class body, instantiate stu2 = LuffyStudent() stu3 = LuffyStudent() print(stu1) # <__main__.LuffyStudent object at 0x10401ae80>
__dict__ method |
self, is the instance itself! When you instantiate it, the python interpreter will automatically pass the instance itself through the self parameter.