Python class and inheritance usage example

Source: Internet
Author: User
This article mainly introduces the usage of python classes and inheritance. The example analyzes the implementation skills of Python class definition and inheritance, which has some reference value, for more information about python classes and inheritance definitions and usage, see the examples in this article. Share it with you for your reference. The details are 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):    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 inheritance:

#!/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()object1.setdata(1234)object1.display()object2 = Twoclass()object2.setdata(1234)object2.display()object3 = Threeclass(12)object3.display()object3.setdata(1234)object3.display()object3 + 22object3.display()object3 * 10object3.display()

I hope this article will help you with Python programming.

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.