Orest Kozyar wrote:
> Given a variable x that can either be None or a tuple of two floats [i.e.
> (0.32, 4.2)], which syntax is considered most appropriate under Python
> coding standards?
>
> if x and x[0] > 0:
> pass
>
> =OR=
>
> if x:
> if x[0] > 0:
> pass
>
On Fri, 14 Sep 2007, Rikard Bosnjakovic wrote:
> For me, "if x" would be enough. If you think it's a bad thing when x
> is of the wrong data, then you really should check that it contains
> *correct* data as well.
That's an okay approach, but, but it's also non-Pythoninc; more of the
look-before
On 14/09/2007, Rikard Bosnjakovic <[EMAIL PROTECTED]> wrote:
> On 14/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote:
> > The second one, which just checks "if x" and is satisfied with any false
> > value, including an empty tuple, does not raise the error condition, even
> > though the data is ba
On 14/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote:
> The second one, which just checks "if x" and is satisfied with any false
> value, including an empty tuple, does not raise the error condition, even
> though the data is bad. This is a bad thing.
For me, "if x" would be enough. If you thi
On Thu, 13 Sep 2007, Adam Bark wrote:
> The problem is what if it's an empty list or tuple? It would pass but have
> not value
> whereas if x would work fine.
Exactly. The poster stated that x is supposed to be either None or a
tuple of two floats.
Just to put a bit of meat on the example, let
On 13/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote:
>
> On Thu, 13 Sep 2007, Orest Kozyar wrote:
>
> > Given a variable x that can either be None or a tuple of two floats [i.e
> .
> > (0.32, 4.2)], which syntax is considered most appropriate under Python
> > coding standards?
> >
> > if x and x
Orest Kozyar wrote:
> Given a variable x that can either be None or a tuple of two floats [i.e.
> (0.32, 4.2)], which syntax is considered most appropriate under Python
> coding standards?
>
> if x and x[0] > 0:
> pass
>
> =OR=
>
> if x:
> if x[0] > 0:
> pass
T
On Thu, 13 Sep 2007, Orest Kozyar wrote:
> Given a variable x that can either be None or a tuple of two floats [i.e.
> (0.32, 4.2)], which syntax is considered most appropriate under Python
> coding standards?
>
> if x and x[0] > 0:
> pass
>
> =OR=
>
> if x:
> if x[0] > 0:
>
The first is how I would code it. Python guarantees that compound
boolean statements are processed from left to right and also that the
AND operator will "short circuit" the rest of the evaluation, since the
rest of the line cannot change the falseness of the entire statement.
Orest Kozyar wr
Given a variable x that can either be None or a tuple of two floats [i.e.
(0.32, 4.2)], which syntax is considered most appropriate under Python
coding standards?
if x and x[0] > 0:
pass
=OR=
if x:
if x[0] > 0:
pass
In the first, I'm obviously making the
10 matches
Mail list logo