Python和缩进,无法入门.

Rec*_*ion 2 python

我刚刚开始学习python并且我被抓住了.我来自C背景.

class Alarm:

    def timer():

    def main():
        print ("Timer has Started")

    main()
Run Code Online (Sandbox Code Playgroud)

当我尝试运行此代码时,我总是遇到一个愚蠢的错误:

alarm > python alarm.py 
  File "alarm.py", line 5
    def main():
      ^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)

Che*_*evy 11

你有一个空的def

def timer():
Run Code Online (Sandbox Code Playgroud)

使用

def timer():
    pass
Run Code Online (Sandbox Code Playgroud)

代替.