定义宠物类型,创建多个宠物,如狗,兔子,猫,鹦鹉,仓鼠,乌龟等,展示每个宠物信息,如颜色,体重等。
3条回答 默认 最新
- 陈年椰子 2022-02-09 11:40关注
class PetClass: def __init__(self, pet_name, pet_color,pet_weight): self.name = pet_name self.color = pet_color self.weight = pet_weight def info(self): return "{},颜色:{},体重:{}".format(self.name,self.color,self.weight) p_cat = PetClass("猫","黑色","5KG") print(p_cat.info()) # 其他宠物自行定义即可
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用