title: How do I get a result (output) from a function? How can I use the result later?
body: <p>Suppose I have a function like:</p>
  <pre><code>def foo():
      x = 'hello world'
  </code></pre>
  <p>How do I get the function to return <code>x</code>, in such a way that I can use it as the input for another function or use the variable within the body of a program? I tried using <code>return</code> and then using the <code>x</code> variable in another function, but I get a <code>NameError</code> that way.</p>
  <hr />
  <p><sub>For the specific case of communicating information <em>between methods in the same class</em>, it is often best to store the information in <code>self</code>. See <a href="https://stackoverflow.com/questions/9520075/">Passing variables between methods in Python?</a> for details.</sub></p>