SyntaxError: 'return' outside function 语法报错

贴出代码

for cc in range(1,11):
    if cc%2==0:
        LL.append(cc*cc)
    return LL

报错`SyntaxError: ‘return’ outside function
仔细查找后
在https://docs.python.org/3/ 官方文档中说明
The key word “return” which should be used only in a function in Python programming language.If you use it in a “for” loop or else,an error like “SyntaxError: ‘return’ outside function” is supposed to appears .

也就是说 return必须在函数或者方法中使用 否则就会这样的语法报错

你可能感兴趣的:(SyntaxError: 'return' outside function 语法报错)