这篇文章主要介绍了Python中类的继承代码实例,本文直接给出代码及运行效果,需要的朋友可以参考下
相对于C 的继承编写,Python更简洁,而且效率也是很高的,下面编写一个简单Python的继承例子。
代码如下:
#!/usr/bin/python
#filename: pyclass.py
class Member:
def __init__(self, name,
age):
self.name =
name
self.age =
age
print 'Member init:%s' %
self.name
def
tell(self):
print 'Name:%s,Age:%d' % (self.name,
self.age),
class Student(Member):
def __init__(self, name, age,
marks):
Member.__init__(self, name,
age)
self.marks =
marks
print 'Student init:%s' %
self.name
def
tell(self):
Member.tell(self)
print 'Marks:%d' %
self.marks
class Teacher(Member):
def __init__(self, name, age,
salary):
#!/usr/bin/python
#filename: pyclass.py
class Member:
class Student(Member):
class Teacher(Member):