Subclass the parent class super reuse capabilities

# class OldboyPeople:
# school = 'oldboy'
# def __init__(self,name,age,gender):
# self.name=name
# self.age=age
# self.gender=gender
# def tell_info(self):
# print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.name,self.age,self.gender))
#
# class OldStudent(OldboyPeople):
# def __init__(self,name,age,gender,course):
# # OldboyPeople.__init__(self,name,age,gender)
# super().__init__(name,age,gender)
# self.course=course
# def learn(self):
# print('%s is learning'%self.name)
# def tell_info(self):
# print('我是学生:',end='')
OldboyPeople.tell_info # (Self)
#
# STU1 = OldStudent ( 'Wanting', 18, 'FEMALE', 'Python')
# stu1.tell_info ()
'' '
I am a student: <Name: <Wanting> Age: <18> sex: <FEMALE>
'' '
# Print (stu1.name, stu1.age, stu1.gender, stu1.course)
' ''
Wanting Python FEMALE 18
'' '
# class OldboyPeople:
# = School' Oldboy '
# DEF the __init __ (Self, name, Age, Gender):
# the self.name name =
# = Age self.age
# self.gender = Gender
# DEF tell_info (Self):
# Print (' <name: <% s> Age: <% s> sex: <% s> '% ( self.name, self.age, self.gender))
#
# class OldStudent(OldboyPeople):
# def __init__(self,name,age,gender,course):
Super # () .__ the init __ (name, Age, Gender)
# = self.course Course
# DEF Learn (Self):
# Print ( '% S IS Learning' the self.name%)
# DEF tell_info (Self):
# Print ( 'I am a student:', End = '')
# Super () tell_info ().
# STU1 = OldStudent ( 'Wanting', 18, 'FEMALE', 'Python')
# stu1.tell_info ()
'' '
I student: <name: <Wanting> Age: <18> gender: <FEMALE>
'' '
# class Foo:
# DEF f1 (Self):
# Print (' Foo.f1 ')
. # Super () F2 ( )
# class Bar:
# DEF F2 (Self):
# Print ( 'Bar.f2')
# Sub class (Foo, Bar):
# pass
# s=Sub()
# print(Sub.mro())
'''
[<class 'in __main __. Sub'>,
<class 'in __main __. Foo'>,
<class 'in __main __. Bar'>,
<class 'Object'>]
'' '
# s.f1 ()
' ''
Foo.f1
Bar.f2
'' '
# class Foo:
# DEF F2 (Self):
# Print (' ==> ')
# DEF F1 (Self):
# Print (' Foo.f1 ')
# Super () F2 (). # is a super long write transfer from the beginning of the current class
# class Bar:
# DEF F2 (Self):
# Print ( 'Bar.f2')
# Sub class (Foo, Bar):
# Pass
# Sub S = ()
s.f1 # ()
'' '
Foo.f1
Bar.f2
' ''
# class Foo:
# def f2(self):
# print('==>')
# def f1(self):
# print('Foo.f1')
# Foo.f2(123)
# class Bar:
# def f2(self):
# print('Bar.f2')
# class Sub(Foo,Bar):
# pass
# s=Sub()
# s.f1()
'''
Foo.f1
==>
'''

Guess you like

Origin www.cnblogs.com/0B0S/p/12088348.html