Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“原因”;返回函数之外的值”;Python中的语法错误?_Python_Syntax Error - Fatal编程技术网

“原因”;返回函数之外的值”;Python中的语法错误?

“原因”;返回函数之外的值”;Python中的语法错误?,python,syntax-error,Python,Syntax Error,我的代码有问题 'return' outside function (<module1>, line 4) <module1> 4 有任何解决方案吗?在此函数中,返回值未正确缩进 def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return words 缩进已关闭,请尝试以下操作: def b

我的代码有问题

'return' outside function (<module1>, line 4)   <module1>   4

有任何解决方案吗?

在此函数中,
返回值未正确缩进

def break_words(stuff):
    """This function will break up words for us."""
    words = stuff.split(' ')
    return words

缩进已关闭,请尝试以下操作:

def break_words(stuff):
    """This function will break up words for us."""
    words = stuff.split(' ')
    return words

缩进是Python的关键组件,与其他一些语言不同,因此确保代码的格式正确非常重要。

缩进在Python中很重要。从您粘贴的内容来看,这里的最后两行不属于break_单词的范围

def break_words(stuff):
    """This function will break up words for us."""
words = stuff.split(' ')
return words

@用户1653037不客气,感谢我们接受您喜欢的任何答案。看见
def break_words(stuff):
    """This function will break up words for us."""
words = stuff.split(' ')
return words