Why am I getting this error in python when i enter into next line of if-else condition?

前端 未结 2 1032
無奈伤痛
無奈伤痛 2021-01-29 09:34
if cake == \"delicious\":
    return \"yes\"

SyntaxError: \'return\' outside function

Why I get like this?

2条回答
  •  梦如初夏
    2021-01-29 10:08

    return is a keyword which can only appear in a function definition (as the syntax error says). You can simply print your output in an if/else block

    if cake == 'delicious': print('yes')   
    

提交回复
热议问题