跟老齐学Python之编写类之四再论继承

773次阅读  |  发布于5年以前

在上一讲代码的基础上,做进一步修改,成为了如下程序,请看官研习这个程序:

复制代码 代码如下:

!/usr/bin/env python

coding:utf-8

class Person:
def init(self, name, email):
self.name = name
self.email = email

class Programmer(Person):
def init(self, name,email,lang, system, website):
Person.init(self,name,email)
self.lang = lang
self.system = system
self.website = website

class Pythoner(Programmer):
def init(self,name,email):
Programmer.init(self,name,email,"python","Ubuntu","qiwsir.github.io")

if name=="main":
writer = Pythoner("qiwsir","qiwsir@gmail.com")
print "name=",writer.name
print "lang=",writer.lang
print "email=",writer.email
print "system=",writer.system
print "website=",writer.website

运行结果

name= qiwsir
lang= python
email= qiwsir@gmail.com
system= Ubuntu
website= qiwsir.github.io

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8