<br><br><div class="gmail_quote">On Sat, Jan 31, 2009 at 4:36 AM, AJ Ostergaard <span dir="ltr"><aj@cubbyhole.net></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I'm not suggesting it's not operating as advertised - I'm suggesting the 'advertising' is slightly sguiffy if you catch my drift. I guess it's just me that finds it slightly counter intuitive. Surely intuitively the expression is "and" and therefore should always return a boolean?</blockquote><div><br>Boolean operators just aren't guaranteed to return a boolean /type/ -- but instead a boolean /expression/, that if evaluated is true or false. The difference is important -- and although it might be partly for historical reasons (after all, there was no boolean /type/ until Python 2.3. That's not really all that long ago), it also has quite a few useful properties that aren't necessecarily immediately obvious but are used in a variety of places.<br><br>A common one is the and/or "ternary" expression that pre-dates the addition of conditional expressions to Python 2.5:<br><br><div style="margin-left: 40px;">>>> test = True<br>>>> test and "Apples" or "Oranges"<br>'Apples'<br>>>> test = False<br>>>> test and "Apples" or "Oranges"<br>'Oranges'<br></div><br>In Python 2.5., that can be rewritten to:<br><br><div style="margin-left: 40px;">>>> test = True<br>>>> "Apples" if test else "Oranges"<br>'Apples'<br>>>> test = False<br>>>> "Apples" if test else "Oranges"<br>'Oranges'<br></div><br>Its part of why you aren't supposed to compare boolean results/tests/expressions against True or False directly usually (besides /just/ style). You do:<br><br><div style="margin-left: 40px;">if expression:<br>   print "Was true!"<br></div><br>Not:<br><br><div style="margin-left: 40px;">if expression is True:<br>    print "Was true!"<br></div><br>--Stephen<br></div></div><br>