Object-oriented technology
- class: used to describe a collection of objects that have the same properties and methods. It defines the properties and methods that are common to each object in the collection. An object is an instance of a class.
- Class variables: class variables are common throughout the instantiated object. Class variables are defined in the class and outside the body of the function. Class variables are not typically used as instance variables.
- data members: class variables or instance variables are used to manipulate the data related to the class and its instance objects.
- method Overloading: If a method inherited from a parent class does not meet the requirements of a subclass, it can be overridden, which is called the override of the method, also known as the overload of the method.
- instance variable: A variable defined in a method that acts only on the class of the current instance.
- inheritance: A derived class (derived class) that inherits the fields and methods of the base class. Inheritance also allows the object of a derived class to be treated as a base class object. For example, there is a design where an object of type dog is derived from the animal class, which is the analog "is a (is-a)" Relationship (example, dog is a animal).
- instantiation: Creates an instance of a class, the concrete object of the class.
- method: a function defined in a class.
- object: An instance of a data structure defined by a class. Object consists of two data members (class variables and instance variables) and methods
class, instance properties, built-in class properties
classpeople: # defines a class name='Ethon' # defines a property #__init__ () is a built-in construction method that automatically calls when an object is instantiated def __init__(self,age): Self.age=AGEP= People (12) # Instantiate an object P PrintP.name# Ethon PrintP.age# APrintPeople.name#EthonPrintPeople.age#the class object people does not own it (so the age property cannot be accessed through the class object)
Inheritance of Classes
classParent:#defining the Parent classparentattr = 100def __init__(self):Print "calling the parent class constructor" defParentmethod (self):Print 'calling the parent class method' defsetAttr (Self, attr): Parent.parentattr=attrdefgetAttr (self):Print "Parent class Properties:", Parent.parentattrclassChild (Parent):#Defining subclasses def __init__(self):Print "calling subclass construction methods" defChildmethod (self):Print 'calling Subclass methods Child method'C= Child ()#instantiating subclassesC.childmethod ()#methods for calling subclassesC.parentmethod ()#calling the parent class methodC.setattr (200)#Call the parent class method againC.getattr ()#Call the parent class method again
The result of the above code execution is as follows:
200
Python Learning Summary 9: Object-oriented