python 笔记

笔记 专栏收录该内容
8 篇文章 0 订阅

继承

class SchoolMember:

'"Represents any school member."'

def __init__(self,name,age):

self.name=name

self.age=age

print '(Inittalized SchoolMember:%s)'%self.name

def tell(self)

'"Tell my details"'

print 'Name:“%s” Age:%s"%(self.name,self.age)

class Teacher(SchoolMember):

''Represent a teacher"'

def __init__(self,name,age,salary):

SchoolMember.__init__(self,name,age)

self.salary=salary

print '(Inittaliwed Teachwe:%s)'%self.name

def tell(self):

SchoolMember.tell(self)

print 'salary:%d'%self.salary


class Student(SchoolMember):

"Represents a student''

def  __init__(self,name,age,marks):

SchoolMemder.__init__(self,name,age)

self.marks=marks

print '(Inittialized Student :%s)'%self.name


def tell(self):

SchoolMember.tell(self)

print 'Marks:%d"%self.marks


t=Teacher('Mes',40,30000)        #(Initialized SchoolMember  )

#(Initialized Teacher)

s=Student('Swaroop',22.75) #(Initalized SchoolMember)

#(Initaikzed Student)

print 

members=[t,s]

for member in members:

member.tell() #Name""Mrs"  Age:40 Salary:30000

#name "swaroop" Age:22 Maeks:75















  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值