1 fromAbcImportAbcmeta, Abstractmethod2 3 classA (metaclass=Abcmeta): called a abstract class4 @abstractmethod5 defTest (self):Pass test is an abstract method and must be implemented by an inherited subclass6 7 8 classB (A):9 PassTen OneB () If you create an object of Class B, you will get an error.
Typeerror:can ' t instantiate abstract class B with abstract methods test
Python3, later, new class, multiple inheritance, method lookup order, breadth first algorithm
1 classA:2 defTest (self):3 Print('In A')4 5 classB (A):6 defTest (self):7 Print('In B')8 super (). Test ()9 Ten classC (A): One defTest (self): A Print('In C') - super (). Test () - the classD (B): - defTest (self): - Print('In D') - super (). Test () + - classE (C): + defTest (self): A Print('In E') at super (). Test () - - classF (D, E): - defTest (self): - Print('In F') - super (). Test () in - to F (). Test () + - Print(F.mro ())
Execution results
inchFinchDinchBinchEinchCincha[<class '__main__. F', <class '__main__. D', <class '__main__. B', <class '__main__. E', <class '__main__. C', <class '__main__. A', <class 'Object';]
Python 17th Day Abstract class