Python,需要缩进块吗?一个并发症

2024-04-26 21:29:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个基于文本的曲棍球团队管理游戏,但是每当我引用我的函数时,我就会得到“预期的缩进块”。不知道我是不是很笨,找不到我的错什么的。你知道吗

    def startup():
        print "Welcome to the Text Based Hockey League!"
        print "You will be tasked with being a team's General Manager"
        yourTeam = raw_input()
    class tbhl:
        def __init__(self):
            self.teamList["Mustangs", "Wolves", "Indians", "Tigers", "Bears", "Eagles", yourTeam]
    class game:
        def __init__(self, homeScore, awayScore):
            #games left in a team class

startup() #<-The line that the error points to
tbhl = tbhl()
print tbhl.teamList[7]

Tags: theto文本selfinitdef曲棍球团队
1条回答
网友
1楼 · 发布于 2024-04-26 21:29:33

当有注释掉的块作为函数的唯一代码时,还可以使用关键字pass来防止此错误。任何开始新一行缩进的代码块都不能留空(或只带注释)

...
class game:
    def __init__(self, homeScore, awayScore):
        #games left in a team class
        pass

pass是一个no-op,当编译器在该缩进级别上查找某些内容时,它会使编译器满意。你知道吗

相关问题 更多 >