马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想把最后两句代码合成一句,和完后为啥运行出来的结果不一样呢
class Potato:
def __init__(self):
self.action = 0
self.zhuangtai = "是生的"
def cook(self,time):
self.action += time
if 0 < self.action <= 3:
self.zhuangtai = "还是生的"
elif 3 < self.action <= 5:
self.zhuangtai = "还是半生不熟"
elif 5 < self.action <= 8:
self.zhuangtai = "终于熟了"
elif self.action > 8:
self.zhuangtai = "烤糊了"
return self.zhuangtai
def __str__(self):
return f"地瓜烤了{self.action}分钟,它{self.zhuangtai}"
digua = Potato()
digua.cook(2)
print(digua)
你这句代码打印的是 digua.cook() 的返回值,而不是 digua
|