Python class and inheritance usage instances

Source: Internet
Author: User
The examples in this article describe Python classes and inheritance definitions and usages. Share to everyone for your reference. Specific as follows:

Class Employee:  Passlee = Employee () lee.name = ' Leefang ' lee.age = 28

Class CAA:  i = 8  def __init__ (self):    self.__a = 7    self.m_a = 1    self.m_b = 2  def __method1 (self): C7/>self.__a + = 1    return self.__a  def Method2 (self, _x):    print self.__method1 (), _xclass CCC:  def METHOD2 (self,_x):    print ' Aaaaaaaaa ' class CBB (CCC, CAA):  def kk (self, _x): Self    . METHOD2 (_x)  def tt (self):    print Self.m_aa = CAA () a.method2 (3) Print A.m_ab = CBB () b.method2 (4) b.kk (' FFFFFF ') B.tt ()

Class inherits as follows:

#!/usr/bin/pythonclass oneclass:  def setdata (self,value):    self.data = value  def display (self):    Print Self.dataclass Twoclass (oneclass):  def display (self):    print "Current value is%s"% Self.dataclass Threeclass (Twoclass):  def __init__ (self,value):    self.data = value  def __add__ (self,other1):    Self.data = Self.data + other1  def __mul__ (self,other2):    self.data = self.data * Other2object1 = Oneclass () obje Ct1.setdata (1234) object1.display () Object2 = Twoclass () object2.setdata (1234) object2.display () Object3 = Threeclass ( Object3.display () object3.setdata (1234) Object3.display () Object3 + 22object3.display () object3 * 10object3.display ()

Hopefully this article will help you with Python programming.

  • 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.