title: Is there any way to execute a statement before each return statement in python function?
body: <p>For example i have this piece of code:</p>
  
  <pre><code>def example():
      a = 'goodbye'
      if True:
          print a
          return 1
      else:
          print a
          return 0
  </code></pre>
  
  <p>I would like to know if there is any possible solution to write once "print a" and execute it before each "return" statement automaticaly. So that if I add more return statements I wouldn't need to add anything, but "print a" would execute. Result would look like something:</p>
  
  <pre><code>def example():
      a = "goodbye"
      """ some code to implement print a """
      if True:
          return 1
      else:
          return 0
  </code></pre>
  
  <p>Each time there is return statement it still would print a.</p>
  
  <p>I tried to google, but don't know how word query, since all results are about returning multiple values.</p>
  
  <p><strong>UPDATE</strong>: My question was answered, thanks to all of you.<br>
  Although wrapping functions are correct answer, but I have chosen answer by <a href="https://stackoverflow.com/a/35338102/3842800">GingerPlusPlus</a> who suggested to use <code>try...finally</code> for simplicity.</p>