<font color="#000000"><br></font><br><div class="gmail_quote">On Mon, Apr 11, 2011 at 7:12 PM, James Mills <span dir="ltr"><<a href="mailto:prologic@shortcircuit.net.au">prologic@shortcircuit.net.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
> Are you saying the two snippets above are equivalent?<br>
<br>
</div>def foo(n):<br>
x = n < 5<br>
if x:<br>
return x<br>
<br>
is functionally equivalent to:<br>
<br>
def foo(n):<br>
return n < 5<br>
<div class="im"><br></div></blockquote><div><br>This is only true if n < 5. Otherwise, the first returns None and the second returns False.<br><br>>>> def foo(n):<br>... x = n < 5<br>... if x: return x<br>
... <br>>>> def foo1(n):<br>... return n < 5<br>... <br>>>> foo(4)<br>True<br>>>> foo1(4)<br>True<br>>>> foo(6)<br>>>> foo1(6)<br>False<br>>>> <br clear="all"></div>
</div><br>--Jason<br>