Syntax error when defining a function on the Python command line

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

    You should add a newline between defining function and calling it:

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

提交回复
热议问题