2020-11-26

面向对象的练习

设计Bird、fish类,都继承自Animal类,实现其方法print_info(),输出信息。

class Animal():
def init(self,age):
self.age = age
def print_info(self):
print(“我今年%d岁了!” % (self.age))
class Bird(Animal):
def init(self, color):
super().init(4)
self.color = color
def print_info(self):
print(“我是一只%s的鸟” % (self.color))
super().print_info()class Fish(Animal):
def init(self, weight):
super().init(2)
self.weight = weight
def print_info(self):
print(“我是一只%d斤重的鱼”%(self.weight))
super().print_info()
bird = Bird(“红色”)
bird.print_info()
fish =Fish(5)
fish.print_info()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值