对象不带参数

object takes no parameters

当我 运行 以下代码时出现上述错误:

class Song(object):
    def _init_(self,lyrics):
        self.lyrics=lyrics

happy_bday = Song([ "happy birthday to you.",
                    "i don't want to get sued.",
                    "so i will stop right here."])

当我从 PowerShell 运行 它时,我得到这个错误:

Traceback (most recent call last):
 File "qa.py", line 12, in <module>
    "so i will stop right here".])
TypeError:object() takes no parameters

您的 init 方法需要两边 2 _,而不仅仅是 1

def __init__(self, lyrics):

再次检查您的源代码。错误消息和您的来源之间存在差异。你的消息来源说:

"so i will stop right here."])

但您的错误消息显示:

"so i will stop right here".])

引号外而不是引号内的句点很重要!