Using try vs if in python
<p>Is there a rationale to decide which one of <code>try</code> or <code>if</code> constructs to use, when testing variable to have a value?  </p>

<p>For example, there is a function that returns either a list or doesn't return a value. I want to check result before processing it. Which of the following would be more preferable and why?</p>

<pre><code>result = function();
if (result):
    for r in result:
        #process items
</code></pre>

<p>or</p>

<pre><code>result = function();
try:
    for r in result:
        #process items
except TypeError:
    pass;
</code></pre>

<h3>Related discussion:</h3>

<p><a href="http://stackoverflow.com/questions/204308/">Checking for member existence in Python</a></p>
