title: Recommended way to initialize variable in if block
body: <p>I have the following code (minus some other operations):</p>
  
  <pre><code>def foobar():
      msg=None
      if foo:
          msg='foo'
      else:
          msg='bar'
      return msg
  </code></pre>
  
  <p>Is the following better practice for the <code>msg</code> variable? </p>
  
  <pre><code>def foobar():
      if foo:
         msg='foo'
      else:
         msg='bar'
      return msg
  </code></pre>
  
  <p>I'm aware that I could simplify the above functions to ternary expressions, however there are operations in each if-else block that I've left out.</p>