我想简单地列出各种咖啡,但收到一个错误,指出该列表未定义。self引用类变量时是否必须在构造函数中使用?
我曾尝试将return语句更改为 return self.coffelist.append(name),但随后出现另一个错误:'Function' object has no attribute 'append'.
class coffe:
coffelist = []
def __init__(self,name,origin,price):
self.name = name
self.origin = origin
self.price = price
return (self.coffelist.append(self.name))
def coffelist(self):
print(coffelist)
c1=coffe("blackcoffe","tanz",55)
c2=coffe("fineroasted","ken",60)
烙印99
呼如林
慕斯709654
相关分类