class Person:
def __init__(self, name):
self.name = name
def harvest(self, crop):
if crop == "死亡的镰刀":
print(f"{self.name}被死亡的镰刀杀死了。")
else:
print(f"{self.name}正在收割{crop}。")
# 创建一个Person对象
person = Person("张三")
# 调用harvest方法模拟收割
person.harvest("小麦")
person.harvest("死亡的镰刀")
标签:pytion,name,self,收割,crop,Person,镰刀,harvest
From: https://blog.51cto.com/u_15917081/9127212