Create a class in Python, execute the program when creating instance attributes, and create a python instance
For example, you can understand the execution process of the program in this way: 1 -- open up a space in the memory to store the created class object, and the Tool (Class Name) points to the memory address of the class object; this type of object stores the property num = 0 (Class Attribute) and method def _ init _ (); 2 -- the program goes down, "Tool (" Shovel ") "an object (Instance Object) is created. This instance object has a special attribute that can help the Instance Object point to the Class Object. When Python automatically executes the init method after creating the instance object, pass custom/default attributes (instance attributes) to the instance object. Then run Tool. num + = 1. Change the value of the class property from num = 0 to num = 1. The program runs here and the init method ends, at this time, the Instance Object already has the instance attribute. The program returns the reference address of the current instance object and assigns it to tool1, which means that tool1 points to this initialized instance object; 3 -- the program continues. "Tool (" ")" is executed in the same way as step 3, but Tool is executed again. num + = 1 once, the value of num = 1 is changed to num = 2; 4 -- the program continues to go down, and "Tool (" Bucket ")" is executed in the same way as step 1, but execute Tool again. num + = 1 once, change the value of num = 2 to num = 3; 5 -- the program has been executed.