子类重用父类的功能
Posted 0b0s
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了子类重用父类的功能相关的知识,希望对你有一定的参考价值。
# class Foo:
# def f1(self):
# print(‘Foo.f1‘)
# def f2(self):
# print(‘Foo.f2‘)
# self.f1()
#
# class Bar(Foo):
# def f1(self):
# print(‘Bar.f1‘)
#
# obj=Bar()
# obj.f2()
# ‘‘‘
# Foo.f2
# Bar.f1
# ‘‘‘
# 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 learn(self):
# print(‘%s is learning‘%self.name)
# def tell_info(self):
# print(‘我是学生:‘,end=‘‘)
# # self.tell_info()
# OldboyPeople.tell_info(self)
#
# stu1=OldStudent(‘婉婷‘,18,‘female‘)
# # teach1=OldTeacher(‘egon‘,28,‘male‘)
# stu1.tell_info()
‘‘‘
我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
‘‘‘
# 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,stu_id):
# self.name=name
# self.age=age
# self.gender=gender
# self.course=course
# self.stu_id=stu_id
# def learn(self):
# print(‘%s is learning‘%self.name)
# def tell_info(self):
# print(‘我是学生:‘,end=‘‘)
# OldboyPeople.tell_info(self)
#
# stu1=OldStudent(‘婉婷‘,18,‘female‘,‘python‘,1)
# stu1.tell_info()
‘‘‘
我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
‘‘‘
# 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,stu_id):
# OldboyPeople.__init__(self,name,age,gender)
# self.course=course
# self.stu_id=stu_id
# def learn(self):
# print(‘%s is learning‘%self.name)
# def tell_info(self):
# print(‘我是学生:‘,end=‘‘)
# OldboyPeople.tell_info(self)
#
# stu1=OldStudent(‘婉婷‘,18,‘female‘,‘python‘,1)
# stu1.tell_info()
‘‘‘
我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
‘‘‘
以上是关于子类重用父类的功能的主要内容,如果未能解决你的问题,请参考以下文章