The difference between classic class and new class, C3 algorithm

Source: Internet
Author: User

The difference between a classic class and a new class

1, only the classic class in the Py2, the new class was added after the 2.2 version. How to differentiate, new class must inherit object after

There are only new classes in Py3. Write not write inheritance, are inherited by default object

2, the lookup order is not the same,

Classic class-depth first, is a way to go to the black

New class-Breadth first (that's less precise), by C3 algorithm, find out the order

Two, C3 algorithm

 

classA (object):PassclassB (A):PassclassC (B):PassclassD (object):PassclassE (d,c):PassclassF (object):PassclassG (F):PassclassH (c,g):PassclassFoo (e,h):Pass#print (E.__mro__) #查找E类的查找顺序#print (h.__mro__)"""L (Foo + L (E) + L (h)) L (e) = E,d,c,b,a,objectl (h) = H,c,b,a,g,f,objectfoo = (object) + (G,f,object) foo,e,d,h,c,b,a,g,f , Object"""Print(Foo.)__mro__)#(<class ' __main__. Foo ';, <class ' __main__. E ';#<class ' __main__. D ';, <class ' __main__. H ';, <class ' __main__. C ';#<class ' __main__. B ';, <class ' __main__. A ';, <class ' __main__. G ';#<class ' __main__. F ';, <class ' object ' >)


Find oral explanations
   Gets the first header and the other table bits to compare
Do not exist then take away.
If present, then discards, and then gets the second table header again compared to the footer of the other table.

The difference between classic class and new class, C3 algorithm

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.