0
我想创建一个方法,该方法需要多个实例的小计(price
属性如下)(返回dog1的总价格dog2 ..如果用户创建带有输入的列表并可能遍历该列表返回宠物订单的总价格)创建并调用类方法
到目前为止,我有这样的:
class dog():
def __init__(self, price, age, food, life):
self.price = int(price)
self.age = int(age)
self.food = str(food)
self.life = int(life)
def subtotal(self):
cost = self.price
return cost
目前还不清楚你到底想做什么。你想知道如何创建一个类的方法,或者你想知道你应该采取什么样的方法来解决你的问题?请显示一些示例代码,告诉您如何使用此类方法将使用的输出结果。 – eestrada