class Message:
def __init__ (self, sender, recipient):
self._sender = sender
self._recipient = recipient
self._body = [sender,'to',recipient,]
def append(self):
self._append = self._body.append(self)
def toString(self):
return self._body
wishList = Message("Annie", "Santa")
wishList.append('For Christmas, I would like:')
wishList.append("A surf board")
wishList.append("An Arduino programming kit")
wishList.append("World peace")`enter code here`
myList = str(wishList.toString)
print(myList)
当我运行时,我在第一个附加项上遇到类型错误“ TypeError:append()接受1个位置参数,但给出了2个位置参数”,我不确定在这里做什么将对您有所帮助。