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

前端 未结 3 1864
刺人心
刺人心 2021-01-22 04:02

I have problem in this code;

\'return\' outside function (, line 4)      4

This code from book called Lea

3条回答
  •  太阳男子
    2021-01-22 04:46

    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.

提交回复
热议问题