title: SyntaxError: 'return' outside function
body: <p>I have a list, somewhat similar to the one below.</p>
  
  <blockquote>
    <p>lines = ['This is line 1',<br>
         'This is another line',<br>
         'This is the third line. Line 03.']</p>
  </blockquote>
  
  <p>When I run the <code>return</code> statement to process for the <code>len</code> of the line, </p>
  
  <pre><code>for line in lines:
      return(len(line))
  </code></pre>
  
  <p>generates the following error:</p>
  
  <blockquote>
    <p>File "", line 2<br>
            return(len(line))<br>
            ^<br>
        SyntaxError: 'return' outside function<br></p>
  </blockquote>
  
  <p>I can however <code>print</code> the lengths of the lines, </p>
  
  <pre><code>for line in lines:
      print(len(line))
  </code></pre>
  
  <p>Result:</p>
  
  <blockquote>
    <p>14 <br>
    20 <br>
    32</p>
  </blockquote>
  
  <p>How exactly is the <code>return</code> statement outside function in this instance?</p>
  
  <p>Edit:
  Here is what it looks like in my Notebook.
  <a href="https://i.stack.imgur.com/x9sGr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9sGr.png" alt="http://imgur.com/w4EzlrH"></a></p>