Python return statement error “ 'return' outside function”

后端 未结 4 1093
别跟我提以往
别跟我提以往 2020-11-29 07:25

When running the following code (in Python 2.7.1 on a mac with Mac OS X 10.7)

while True:
    return False

I get the following error

<
4条回答
  •  忘掉有多难
    2020-11-29 07:53

    The return statement only makes sense inside functions:

    def foo():
        while True:
            return False
    

提交回复
热议问题