Python 17th Day Abstract class

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.