类文件 class1.py
class People(): def __init__(self,name,sex,age): self.name=name self.sex=sex self.age=age def tezheng(self,zhiye,aihao,xueli): miaoshu=self.name+","+self.sex+",今年"+self.age+" 岁,"+xueli+"学历 ,从事"+zhiye+"工作,平时喜欢"+aihao return miaoshu
# humen=People("小明","男","24") # htz=humen.tezheng("小编","吹水","吹牛本科") # print(htz)
class Car(): def __init__(self,lunzi,renshu,youhao): self.lunzi=lunzi self.renshu=renshu self.youhao=youhao def zhonglei(self,name,leixing,zuoyong): lx=name+'这是'+leixing+'类车,可做'+zuoyong return lx class Car1(Car): def __init__(self,lunzi,renshu,youhao,chepai): self.lunzi=lunzi self.renshu=renshu self.youhao=youhao self.chepai=chepai def shijian(self,name,pinpai,shiqing): sj=name+'驾驶者自己的'+pinpai+shiqing+',车牌号是:'+self.chepai return sj # carman=Car1('4','4','2.5','12345678') # cm=carman.zhonglei('宝马','A','泡妞')
# print(cm) =================================================================================== 主程序文件代码 方法一: from class1 import People,Car1 p1=People('老王','男','21') pt=p1.tezheng('拉皮条','赌钱','小学没毕业') print(pt)
c1=Car1('3','5','1.5','68791') cc=c1.shijian('明明','宝鸡','卖肉') ct=c1.zhonglei('小明','碰碰车','玩着') print(cc) print(ct) 方法二: import class1 p1=class1.People('老王','男','21') pt=p1.tezheng('拉皮条','赌钱','小学没毕业') print(pt)
c1=class1.Car1('3','5','1.5','68791') cc=c1.shijian('明明','宝鸡','卖肉') ct=c1.zhonglei('小明','碰碰车','玩着') print(cc) print(ct)
|