China Hong
2021-03-12 17:05
采纳率: 100%
浏览 27

小白疑问:哪里出问题了

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"])

 

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()

运行结果:

Traceback (most recent call last):
  File "C:\Users\86155\temp\ex40.py", line 10, in <module>
    happy_bday = Song(["Happy birthday to you",
TypeError: Song() takes no arguments

为什么会这样?

2条回答 默认 最新

相关推荐 更多相似问题