Syntax error when defining a function on the Python command line

前端 未结 4 1617
感动是毒
感动是毒 2021-01-21 05:29

I am trying to define a function on the Python REPL. Every time I try to run the below code, I get a syntax error.

Code:

def hello():
    print (\"Hello!         


        
4条回答
  •  面向向阳花
    2021-01-21 05:45

    It looks like you've entered the whole block as a single statement. You'll need to hit enter after entering:

    def hello():
        print ("Hello!")
    

    So that the interpreter understands that this is a single definition that you've entered. Once that's been defined, then try running the hello() function.

提交回复
热议问题