Cause of “return outside of function” syntax error in Python?

∥☆過路亽.° 提交于 2019-12-02 01:28:57

in this function the return is not properly indented.

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

Your indentation is off, try this:

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

Indentation is a key component of Python, unlike some other languages - so it is important to ensure that your code is properly formatted.

Indentation matters in python. From what you've pasted the last two lines here are NOT int the scope of break_words.

def break_words(stuff):
    """This function will break up words for us."""
words = stuff.split(' ')
return words
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!