1. What is an object?
The source of the object is to simulate the real world and encapsulate the data and code together. People, cars, houses, are the real world.
Object = Feature (attribute) + method (behavior)
property is actually a variable in the code.
Methods are functions that perform certain tasks by invoking these functions.
Instantiated object: TT (variable) = class name () assignment operation is not required, but if the created object is not assigned to a variable, then the object cannot be used because no reference pointer points to the instance and will eventually be automatically reclaimed by the Python garbage collection mechanism.
How to call the object's method, via TT (variable). method
The Magic method of a class: Constructs a method, as long as an object is instantiated, and this method is called automatically when the object is instantiated. Arguments are passed in when instantiated, and these parameters are automatically passed into the __init__ method. By overriding this method, the process of customizing the initialization of the object
Call each other:
2. What is a class? What is the class for?
Class Description: A class is a kind of thing, a model, which contains objects (methods and properties), by using a class to create a real object, this object is called an instance of this class, also known as an instance object.
Types usually start with uppercase letters.
When the class is instantiated, it should not pass arguments, depending on the constructor.
A better understanding of the class, give two examples
EG1: Factory to produce a batch of toys, is not to create models of toys, according to the model for mass production, is the real toy. Toy model is the class, the real toy is the object of the class instance.
EG2: Building before building, must need the building structure of drawings (including the properties of the building: several floors, how much money, etc., the method of building: Sales, buy people, etc.)
Definition class: Class name:
Object-Oriented Programming
Object-oriented inside is a process-oriented
What is self? Self is the object of this class. Equivalent to a unique designation. How a class is likened to an instance of a drawing class The object is a real house, according to a drawing can be instantiated, thousands of houses, they look similar, but they have their own home. Self is equivalent to the house number. With self, you can easily find your own house.
Python------Object-oriented programming