title: Execute function only if a variable is True
body: <p>I would like to run a function only if a statement is True.
  For example, i have:</p>
  
  <pre><code>def foo():
      # do something
  </code></pre>
  
  <p>And i want to run this only when</p>
  
  <pre><code>var == True
  </code></pre>
  
  <p>And in key handler I <strong>don't</strong> want to do something like this:</p>
  
  <pre><code>if k.key() == Key_UP and var:
      foo()
  </code></pre>
  
  <p>I call this function from multiple places and I don't want to repeat var condition.
  Also, I <strong>don't</strong> want something like this:</p>
  
  <pre><code>def foo():
      if var:
          # do something
  </code></pre>
  
  <p>The last one I showed is the nearest to my needs, but still i think it can be done some other way. Idiomatic for Python 3.</p>
  
  <p>Greetings!</p>
  
  <p>PS. I want to get something like this:</p>
  
  <pre><code>def foo() if var == True:
      # do something
  </code></pre>