使用Python类向发件人,收件人和正文发送消息

时间:2018-12-06 21:54:45

标签: python string list class append

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个位置参数”,我不确定在这里做什么将对您有所帮助。

0 个答案:

没有答案
相关问题