class Product(object):
def __init__(self, ind, name, price, quantity):
self.ind = ind
self.name = name
self.price = price
self.quantity = quantity
inventory = list()
def add(self):
inventory.append(Product(self.ind))
inventory.append(Product(self.name))
inventory.append(Product(self.price))
inventory.append(Product(self.quantity))
print('product %s added')%name
Product.add(63456, 'Meow', 60.00, 0)
我仍然得到一個錯誤的方法時:類型錯誤調用類
Product.add(63456, 'Meow', 60.00, 0)
TypeError: unbound method add() must be called with Product instance as first argument (got int instance instead)
,我不知道,因爲我剛開始學習班什麼是錯。
什麼需要改變?
你的代碼中包含大量的錯誤。我認爲最好是在繼續之前備份並閱讀[基本Python教程](https://docs.python.org/3/tutorial/index.html)。一旦理解了Python的基礎知識,就可以繼續學習更高級的主題,如類和OOP。 – iCodez
你是指什麼錯誤? – Iwko