Re: [Tutor] comparison bug in python (or do I not get it?)

2008-03-01 Thread bob gailer
Ricardo Aráoz wrote: > Just one further question : > > >>> 1 == True > True > >>> 5 == True > False > > and yet > > >>> if 5 : print 'True' > True > > > I thought a non-zero or non-empty was evaluated as True. Now in the 5 == > True line I'm not saying "5 is True", shouldn't it evaluate just li

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-03-01 Thread Kent Johnson
Ricardo Aráoz wrote: > >>> 1 == True > True Yes, True is an integer with value 1. Actually True is a bool but bool is a subclass of int: In [3]: type(True) Out[3]: In [4]: isinstance(True, int) Out[4]: True In [5]: int(True) Out[5]: 1 > >>> 5 == True > False Right, because 5 != 1 > and yet

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-03-01 Thread Ricardo Aráoz
Hans Fangohr wrote: > Hi Kent, > >> Hans Fangohr wrote: >> >>> In [2]: 2 in [1,2,3] == True >>> Out[2]: False >>> >>> Why does [2] return False? Would people agree that this is a bug? >> No, not a bug. Don't be too quick to blame your tools! > > That's good news. I'd be worried if this wasn't the

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-02-29 Thread Steve Willoughby
Kent Johnson wrote: > Hans Fangohr wrote: > >> In [2]: 2 in [1,2,3] == True On a slightly different tangent from the other answers you've received to this question, if you're using a conditional expression, don't compare it explicitly with True or False, just state the condition: if 2 in [1,2,

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-02-29 Thread Luciano Ramalho
On Fri, Feb 29, 2008 at 10:21 AM, Kent Johnson <[EMAIL PROTECTED]> wrote: > No, not a bug. Don't be too quick to blame your tools! Well said, Kent. Here's a generic tip to anyone learning Python. I learned Python after working professionally with several languages for many years, including Java

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-02-29 Thread Hans Fangohr
Hi Kent, > Hans Fangohr wrote: > >> In [2]: 2 in [1,2,3] == True >> Out[2]: False >> >> Why does [2] return False? Would people agree that this is a bug? > > No, not a bug. Don't be too quick to blame your tools! That's good news. I'd be worried if this wasn't the desired behaviour -- I just hadn

Re: [Tutor] comparison bug in python (or do I not get it?)

2008-02-29 Thread Kent Johnson
Hans Fangohr wrote: > In [2]: 2 in [1,2,3] == True > Out[2]: False > > Why does [2] return False? Would people agree that this is a bug? No, not a bug. Don't be too quick to blame your tools! The equivalent expression is In [1]: (2 in [1,2,3]) and ([1,2,3]==False) Out[1]: False 'in' is conside

[Tutor] comparison bug in python (or do I not get it?)

2008-02-29 Thread Hans Fangohr
Dear Python folks, here is a sequence of commands (ipython) that lead to a question. See my comments after leading '#': In [1]: 2 in [1,2,3] Out[1]: True #nothing special here, of course 2 is in the list. In [2]: 2 in [1,2,3] == True Out[2]: False #This is somewhat surprising, as one would ho