Python's brief talk about new and old class (or classic Class)

Source: Internet
Author: User

#_ *_coding:utf-8 _*_#: The difference between a classic class and a new class # Parent class Class father (object):     def __init__ (self):         self. fname =  ' fffffff '         print  ' father.__init__ '      def func (self):        print  ' FUNCFURNC '     def bar (self):        print  ' Barbarbar '     def test (self):  #再定义一个方法          print  ' 11111 '         print  ' testtest ' #子类继承父类, That means the Son class can get the Father class method Class son (Father):     def __init__ (self):         self. sname =  ' Sonsonson '         print  ' son.__init__ '          fatHer.__init__ (self)   #调用父类的构造函数, this is the first form, this way can not inherit object         Super (Son, self). __init__ ()   #调用父类的构造函数, which is the second form that must inherit Object    def yes (self):         print  ' Barbarbar '     def test ( Self):        print  ' aaaaaaaa '     # Override the parent class's Test method # to instantiate the subclass, trying to access the method S1 = son ()   #实例化子类s1 in the parent class. Bar ()      #成功访问父类的方法s1. Test ()     #访问重写后的方法 ' ' Other instructions: If you inherit object  then it is the new class,  recommend the use of modern class if there is no inheritance object  that is the classic class difference: Classic class , the use of depth-first traversal of the parent class in multiple inheritance, and a new C3 algorithm to traverse the parent class when multiple inheritance


This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1874428

Python's brief talk about new and old class (or classic 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.