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.