码迷,mamicode.com
首页 > 其他好文 > 详细

pyhton类集成

时间:2015-03-01 21:00:54      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

class SchoolMember:
  def __init__(self,name,age):
    self.name = name
    self.age = age
    print ‘init SchoolMember: ‘, self.name
  def tell(self):
    print ‘name:%s; age:%s‘ % (self.name, self.age)
class Teacher(SchoolMember):
  def __init__(self,name,age,salary):
    SchoolMember.__init__(self,name,age)
    self.salary = salary
    print ‘init Teacher: ‘, self.name
  def tell(self):
    SchoolMember.tell(self)
    print ‘salary: ‘, self.salary
class Student(SchoolMember):
  def __init__(self,name,age,marks):
    SchoolMember.__init__(self,name,age)
    self.marks = marks
    print ‘init Student: ‘, self.name
  def tell(self):
    SchoolMember.tell(self)
    print ‘marks: ‘, self.marks
t = Teacher(‘yanggang‘, 20, 1000)
s = Student(‘liming‘, 12, 86)
members = [t,s]
print
for member in members:
  member.tell()

pyhton类集成

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4307548.html

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