37,718
社区成员
发帖
与我相关
我的任务
分享
__init__
你写的是 _init_
前后是两个下划线 。class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_a_song(self):
for line in self.lyrics:
print line
happy_bday = Song(["Happy birthday to you",
"I don`t want to get sued",
"So I`ll stop right there"]) #TypeError
bulls_on_parade = Song(["They rally around the family",
"With pockets full of shells"])
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()