[Tutor] evaluating AND
ricaraoz at gmail.com
Fri Sep 14 17:24:07 CEST 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:
> if x:
> if x > 0:
> In the first, I'm obviously making the assumption that if the first
> condition evaluates to false, then the second condition won't be evaluated.
> But, is this a good/valid assumption to make? Is there a more appropriate
> design pattern in Python?
What about exceptions ?
if x > 0:
pass # process the item
pass # or do whatever you want if there's no item
More information about the Tutor