): print ' Enter F ' super (F, self). __ Init__ () # change print "Leave F"
f = f (), execution result:
Enter F Enter e enter B Enter C Enter D Enter a leave a leave D leave C leave B leave E leave FAs can be seen, the initialization of F not only completes all calls to the parent class, but also guarantees that the initialization function of each parent class is called only once.
Summary
1. Super is not a function, it is a class name, like Super (B, self) actually called
This article mainly introduces the question about the inheritance relation of the overloaded isinstance in Python, has certain reference value, now share to everybody, the need friend can refer to
Judging inheritance Relationships
The built-in method Isinstance (object, ClassInfo) can determine whether an object is an instance of a class. This relationship can b
Multiple inheritance: (Implements the function of the parent class by inheriting subclasses)
Animal may have different classifications:Animal------Mammal------BirdAnimal------Run------FlyFor each animal dog,cat, parrot may be the first category, or it may inherit the second classification at the same time. The dumb way is to define Runmammal,flymammal,flybird. But when more classifications are needed, it is obviously unreasonable. ------Multiple
Class S_all (METACLASS=ABC. Abcmeta): #python2.7 Use this method to define interface inheritance # __metaclass__ = abc. Abcmeta @abc. Abstractmethod def read (self): Passpyhton2.7 will error, this method is used for python3+pyhton2.7 Application Sub-method definitionClass S_all (): #python2.7 Use this method to define interface inheritance __metaclass__ = abc. Abcmeta @abc. Abstr
Python inherits that subclasses can override various methods of the parent class, including the __init__ method.If you want to overwrite the __init__ method of the parent class, and you want to refer to the __init__ method of the parent class in the overridden method, such as adding some properties to the __init__ method of the parent class or something else.You need to display a method that references the parent class, otherwise the parent class's me
Code: Class A (): def Add (self,a,b): return A+bclass B (A): Def sub (self,a,b): Return A-bprint (b (). Add (4,5) )Results:Python 3.5.2 (V3.5.2:4DEF2A2901A5, June, 22:18:55) [MSC v.1900-bit (AMD64)] on Win32type "copyright", "credits" or "license ()" For more information.>>> ======================= restart:d:/selenium/test/5.py ============== =========9>>>Analysis: Method exists in parent Class A: Add ()Subclass B Inherits parent Class A through B (a)You can therefore use the Add method in a par
In inheritance we call the parent class: parent class, Base class, Super classRefer to Subclass: subclass, derived class, inheriting classThe child class and the parent class are the relationships of is.If: P1 is an instance of the parent class, we can say that P1 is a parent class, but it cannot be said to be a subclass.P2 is an example of a subclass, and we can say that P2 is a subclass, or P2 is a parent class.class person (object): def __init_
First, review:1, the process: The core is the process, the process is the steps to solve the problem, that is, what to do first, what to do, based on process-oriented design procedures, like in the design of a pipeline, is a mechanical thinking method.Pros: Complex questions to simplifyCons: Poor scalability (holding a body)Application scenario: Linux kernel, httpd,git2, Object-oriented programming: The core is the object, to understand the object should regard themselves as God, in the eyes of
# _*_ Coding:utf-8 _*___author__ = ' Pythonwu '__date__ = "2018/7/2 14:50"Class A (): def getValue (self): Print (' return value of A ') Def show (self): Print (' I can show A ')Class B (A): def getValue (self): Print (' return value of B ')Class C (A): def getValue (self): Print (' return value of C ') Def show (self): Print (' I can show C ')Class D (B,C): PassD = d ()D.show ()D.getvalue ()From Pprint import PprintPprint (D.mro ())I can show
First, the main content:Interface class: ( Only in the work, writing a specification.)Abstract class:Usefulness: At work, if you prescribe several classes, you must have the same method, if you are abstract class.Packaging:1, put some properties or methods (some useful information) in a space.2, Private member encapsulation: private static variable, private property, Private method feature: +__ double underline before variable, and outside class, subclass accesses private variable, private metho
Interface inheritance is also called the normalization design of the program, and this kind of thing is called abstract class.So what is abstract class?Abstract class This kind of thing, can only be inherited, can not be instantiated.If a class is extracted from a bunch of objects, an abstract class is extracted from a bunch of classes.Simply put, the biggest difference between abstract class and ordinary class is that abstract class methods are tried
Data encapsulation, inheritance and polymorphism are the three main characteristics of object-oriented.Data encapsulation:In a class, such as the student class (initialization and name and score two properties), each instance has its own name,score of the data. We can access this data through functions, such as printing a student's score. Directly define an output function, output name and corresponding score.However, since the student instance itself
function, all properties and methods are Animal the parent class of cat C = (cat) A; To useIn the example above, when the variable type is the parent class or interface of the instance type, there are differences in compile and run:
Member variables: Both compile and run refer to animal = left!
Method: Compile Reference animal = left, parent class has only compile pass, run priority reference Cat is reference = right. (The method of a subclass is still used in the case of duplicate
#coding: Utf-8 "" "Term: 1, in Python3, custom-created classes are inherited by default in the Python class named Object Class 2, the object class provides methods, is a double underscore, is to provide for Python internal use 3, The inherited class is called a superclass, or a class called the parent class 4, inherited from the superclass (parent class) is called Subclass 5, the subclass derives from the p
Python, like C + +, supports multiple inheritance. The concept is easy, but the hard work is that if subclasses call an attribute that is not defined by itself, it is in what order it goes to the parent class, especially if many of the parent classes contain the same attribute.
For both classical and new classes, the search order for attributes is different. Now let's look at two different manifestations o
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.