title: Does Python optimize away a variable that's only used as a return value?
body: <p>Is there any ultimate difference between the following two code snippets? The first assigns a value to a variable in a function and then returns that variable. The second function just returns the value directly.</p>
  
  <p>Does Python turn them into equivalent bytecode? Is one of them faster?</p>
  
  <p><strong>Case 1</strong>:</p>
  
  <pre><code>def func():
      a = 42
      return a
  </code></pre>
  
  <p><strong>Case 2</strong>:</p>
  
  <pre><code>def func():
      return 42
  </code></pre>