python objects, Classes
First, python the class
A class can be likened to a description of a collection of types
The same kind of thing is called a class, it has the same attributes (in fact, variable) description, which encapsulates the same method. For example, a car is a class that includes attributes such as Price, brand, and so on.
Second, python Object
Python uses the object model to store data. Constructing a value of any type is an object.
All Python objects have three properties: identity , type , value
identity : Each object has a unique identity, and any object's identity can be obtained using the built-in function ID ()
type : The type of an object determines what type of value the object can hold, what operations can be done, and what rules to follow. You can use the type () function to view the types of Python objects. Type () returns an object instead of a simple string.
value : The data represented by the object.
A piece of code to explain the image of the class and objects, HP, Lenovo are a computer, different computers have different brands, different prices,
Therefore, the notebook computer laptop means "computer" this kind of thing, the computer has many attributes, such as the brand, the price and so on. And Hp,lenovo is a computer this big class of one, it is specific, has its own individual price and brand, so HP, Lenovo is an object of laptop that above def printlaptop (self) is what, it represents the object.
The parameters of the Lenovo object that we call function simultaneous Lenovo.type, Lenovo.price are received by the Printlaptopinfo function in the class as self, so we naturally become self when we use arguments. Type, Self.price. The initialization of the object in the tag is the assignment to the object's properties.
With classes there are encapsulation, inheritance, polymorphic
polymorphic:
Polymorphism is a polymorphic form that determines its state at runtime and cannot determine its type at compile time. Polymorphism in Python is a bit different from Java in C + +, and variables in Python are dynamic types that are defined without specifying their type, which determines the type of the variable at run time, as needed.
Python itself is an explanatory language, not precompiled, so it only determines its state at run time, so some people say Python is a polymorphic language. Many places in Python can be characterized by polymorphism, such as the built-in function Len (object), the Len function can not only calculate the length of the string, but also to calculate the list, tuples and other objects in the number of data, here at run time through the parameter type to determine its specific calculation process, It is a manifestation of polymorphism.
PS: Not finished, to be continued .....
Python objects, classes