python实现shape类的多态_python 类的多态

# #多态的概念指出了对象如何通过他们共同的属性和动作来操作及访问,而需要考虑他们具体的类

# #反应在执行不同实例的相同方法 后的状态,python本身就是多态的

# #多态继承的一个体现方式

# class H2O:

# def __init__(self,name,temperature):

# self.name=name

# self.temperature=temperature

# def turn_ice(self):

# if self.temperature < 0:

# print('[%s]温度太低了,结冰了' %self.name)

# elif self.temperature >0 and self.temperature < 100:

# print('[%s]液化成水' %self.name)

# elif self.temperature > 100:

# print('[%s]温度太高变成了水蒸气' %self.name)

#

# class Water(H2O):

# pass

# class Ice(H2O):

# pass

# class Steam(H2O):

# pass

#

# w1=Water('水',23)

# i1=Ice('冰',-20)

# s1=Steam('蒸汽',233)

#

# w1.turn_ice()

# i1.turn_ice()

# s1.turn_ice()

#

# def func(obj):

# obj.turn_ice()

# print('----------------------------')

# func(w1)

# func(i1)

# func(s1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值