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
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
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
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,
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
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
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
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