码迷,mamicode.com
首页 > 编程语言 > 详细

Python__子类调用父类的方法

时间:2017-08-18 19:54:56      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:讲师   ati   tin   tle   父类   test   bsp   pass   方法   

# class OldboyPeople:
# school = ‘oldboy‘
# def __init__(self,name,age,sex):
# self.name=name
# self.age=age
# self.sex=sex
#
# def eat(self):
# print(‘is eating‘)
# def teach(self):
# print(‘这是父类的teach‘)
#
# class OldboyTeacher(OldboyPeople):
# def __init__(self,name,age,sex,salary,title):
# # OldboyPeople.__init__(self,name,age,sex)
# #在Python2中需要写全:super(OldboyTeacher,self)
# super().__init__(name,age,sex)
# self.salary=salary
# self.title=title
#
# def teach(self):
# # OldboyPeople.teach(self)
# super().teach()
# print(‘%s is teaching‘ %self.name)
# print(OldboyTeacher.mro())
#
# egon_obj=OldboyTeacher(‘egon‘,18,‘male‘,3.1,‘沙河霸道金牌讲师‘)
# # print(egon_obj.title)
# # print(egon_obj.__dict__)
# egon_obj.teach()

 

 

 

class A:
def test(self):
super().test()

class B:
def test(self):
print(‘B‘)

class C(A,B):
pass

# a=A()
# a.test()

print(C.mro())
c=C()
c.test()

Python__子类调用父类的方法

标签:讲师   ati   tin   tle   父类   test   bsp   pass   方法   

原文地址:http://www.cnblogs.com/wangmengzhu/p/7391162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!