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

…衆ロ難τιáo~ 提交于 2021-02-05 12:18:32

问题


if cake == "delicious":
    return "yes"

SyntaxError: 'return' outside function

Why I get like this?


回答1:


You can create some functions like this.

text  ="delicious" 
def check(text):
    if text=="delicious":
        return 'yes'

check(text)



回答2:


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')   


来源:https://stackoverflow.com/questions/52773539/why-am-i-getting-this-error-in-python-when-i-enter-into-next-line-of-if-else-con

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!