The difference between the new class and the classic class of 03-python

Source: Internet
Author: User

The new class is the class person (object): This form, from the beginning of the py2.2

The new class adds:

 is the attribute's name.  is the attribute's docstring. __get__ (object is fromobject. __set__ (objectObject to value.__delete__ (objectobject.

The emergence of the new class, in addition to a large number of methods, but also changed the classic Class A multi-inheritance bug, because it uses a breadth-first algorithm

23. The default is the new class in X, and the classic class is removed without having to explicitly inherit the object

Paste a section of the official online author explained

If there is a Save method in the classic class, and C overrides the Save () method, then the search order is d->b->a and will never find C.save ()

Code Demo:

#!/usr/bin/Env Python3#coding:utf-8" "the difference between the new class and the classic class, multiple inheritance code demo" "classa:def __init__ (self): print'This is A'def Save (self): print'Save method from A'classb:def __init__ (self): print'This is B'classc:def __init__ (self): print'This is c'def Save (self): print'Save method from C'classD (B, C): Def __init__ (self): print'This is D'D=D () d.save ()

The results show A,

Note: In later versions of Python3, the new class is used by default and will not succeed

The difference between the new class and the classic class of 03-python

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.