Syntax error when defining a function on the Python command line

前端 未结 4 1615
感动是毒
感动是毒 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:46

    Press enter once after defining your function (that is, enter one blank line). Essentially, this lets Python know that you are done defining your function.

    Once you see >>> again, you can call your function.

    See the picture for how it should look when done right:

提交回复
热议问题