On 13/09/2007, <b class="gmail_sendername">Terry Carroll</b> <<a href="mailto:carroll@tjc.com">carroll@tjc.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, 13 Sep 2007, Orest Kozyar wrote:<br><br>> Given a variable x that can either be None or a tuple of two floats [i.e.<br>> (0.32, 4.2)], which syntax is considered most appropriate under Python<br>> coding standards?
<br>><br>> if x and x[0] > 0:<br>> pass<br>><br>> =====OR=====<br>><br>> if x:<br>> if x[0] > 0:<br>> pass<br><br>I would like either one if instead of "if x" you used "if x is not None";
<br>that seems a lot easier to me to read. It's a bit jarring to see the same<br>variable used in one expression as both a boolean and a list/tuple.<br><br>Besides, suppose somehow x got set to zero. It would pass without error,
<br>something you wouldn't want to have happen. Even if you've set things up<br>so that it couldn't happen, it's not obvious from looking at this code<br>that it couldn't happen.<br><br>If you really want to test for x being non-None, test for x being
<br>non-None.</blockquote><div><br>The problem is what if it's an empty list or tuple? It would pass but have not value<br>whereas if x would work fine. <br></div><br></div><br>