Introduction to python object-oriented technology
Class (Class): used to describe a collection of objects with the same attributes and methods. It defines the properties and methods common to every object in the collection. Objects are instances of classes. (Recommended learning: Python video tutorial)
Class variables: Class variables are public throughout the instantiated object. Class variables are defined in the class and outside the function body. Class variables are generally not used as instance variables.
Data members: Class variables or instance variables are used to process data related to the class and its instance objects.
Method rewriting: If the method inherited from the parent class cannot meet the needs of the subclass, it can be rewritten. This process is called method override, also known as method rewriting.
Instance variables: Variables defined in methods only act on the class of the current instance.
Inheritance: That is, a derived class inherits the fields and methods of the base class. Inheritance also allows an object of a derived class to be treated as a base class object. For example, there is such a design: an object of type Dog is derived from the Animal class, which simulates the "is-a" relationship (for example, Dog is an Animal).
Instantiation: Create an instance of a class, a specific object of the class.
Method: Function defined in the class.
Object: Data structure instance defined through a class. Objects include two data members (class variables and instance variables) and methods.
Classes in Python provide all the basic functions of object-oriented programming: The inheritance mechanism of classes allows multiple base classes. Derived classes can override any method in the base class. Methods can Call the method of the same name in the base class. Objects can contain any amount and type of data.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to understand python classes. For more information, please follow other related articles on the PHP Chinese website!