Steven D'Aprano wrote:
> Or wait, I have thought of one usage case: if you are returning a value
> that you know will be used only as a flag, you should convert it into a
> bool. Are there any other uses for bool()?
We could, of course, get along without it. One use for
canonical true and false v
On Thursday 22 September 2005 07:09 pm, Ron Adam wrote:
> Terry Hancock wrote:
> > On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
> True and True
> >
> > True
> >
> > Also makes sense (and this is indeed what happens).
>
> Only because True is the last value here. ;-)
Nope, works f
Terry Reedy wrote:
> "Steve Holden" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>Which is yet another reason why it makes absolutely no sense to apply
>>arithmetic operations to Boolean values.
>
>
> Except for counting the number of true values. This and other legitimate
Terry Hancock wrote:
> On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
>
>>Steve Holden wrote:
>>
>>>Ron Adam wrote:
>>>
>>> True * True
1 # Why not return True here as well?
>>>
>>>Why not return 42? Why not return a picture of a banana?
>>
>>My question st
On Thu, 22 Sep 2005 14:12:52 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
>
>"Steve Holden" <[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
>> Which is yet another reason why it makes absolutely no sense to apply
>> arithmetic operations to Boolean values.
>
>Except for counting t
On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
> Steve Holden wrote:
> > Ron Adam wrote:
> >> >>> True * True
> >> 1 # Why not return True here as well?
> >>
> > Why not return 42? Why not return a picture of a banana?
>
> My question still stands. Could it be helpful
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Which is yet another reason why it makes absolutely no sense to apply
> arithmetic operations to Boolean values.
Except for counting the number of true values. This and other legitimate
uses of False/True as 0/1 (inde
Steve Holden wrote:
> Ron Adam wrote:
>>
>> 2. Expressions that will be used in a calculation or another
>> expression.
>>
> By which you appear to mean "expressions in which Boolean values are
> used as numbers".
Or compared to other types, which is common.
>> This matters because if you
Ron Adam wrote:
> Steven D'Aprano wrote:
>
>
>>>So..
>>>
>>> bool(a and b) * value
>>>
>>>Would return value or zero, which is usually what I want when I do this
>>>type of expression.
>
>
>>That's all very interesting, and valuable advice for somebody who doesn't
>>understand how Python's l
Steven D'Aprano wrote:
> Ah, that's a good example, thanks, except I notice you didn't actually
> cast to bool in them, eg: (min < value < max) * value
It wasn't needed in these particular examples. But it could be needed
if several comparisons with 'and' between them are used.
It just seems o
On Wed, 21 Sep 2005 18:53:34 +, Ron Adam wrote:
> Steven D'Aprano wrote:
>
>>>So..
>>>
>>>bool(a and b) * value
>>>
>>>Would return value or zero, which is usually what I want when I do this
>>>type of expression.
>
>> That's all very interesting, and valuable advice for somebody who do
> On Wed, 21 Sep 2005 09:03:00 +1000, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>>In practice, how often do you really care that your truth values have the
>>specific values 0 and 1 rather than anything false and anything true? In
>>what circumstances?
Another example: you have an exam with N
Steven D'Aprano wrote:
>>So..
>>
>>bool(a and b) * value
>>
>>Would return value or zero, which is usually what I want when I do this
>>type of expression.
> That's all very interesting, and valuable advice for somebody who doesn't
> understand how Python's logical operators work, but the qu
On Wed, 21 Sep 2005 09:03:00 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Tue, 20 Sep 2005 03:03:15 +, Ron Adam wrote:
>
>> Steven D'Aprano wrote:
>>> Are there actually any usage cases for *needing* a Boolean value? Any
>>> object can be used for truth testing, eg:
>
>[snip]
>
>> Of
On Tue, 20 Sep 2005 03:03:15 +, Ron Adam wrote:
> Steven D'Aprano wrote:
>> Are there actually any usage cases for *needing* a Boolean value? Any
>> object can be used for truth testing, eg:
[snip]
> Of course if any of the default False or True conditions are
> inconsistent with the logic
On Mon, 19 Sep 2005 22:31:05 +, Bengt Richter wrote:
> On Mon, 19 Sep 2005 23:46:05 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>Are there actually any usage cases for *needing* a Boolean value? Any
>>object can be used for truth testing, eg:
[snip]
> making an index (it's an int sub
Steven D'Aprano wrote:
> On Mon, 19 Sep 2005 12:16:15 +0200, sven wrote:
>
>
>>to make sure that an operation yields a boolean value wrap a bool()
>>around an expression.
>>None, 0 and objects which's len is 0 yield False.
>>so you can also do stuff like that:
>
>
> Are there actually any usa
On Mon, 19 Sep 2005 23:46:05 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Mon, 19 Sep 2005 12:16:15 +0200, sven wrote:
>
>> to make sure that an operation yields a boolean value wrap a bool()
>> around an expression.
>> None, 0 and objects which's len is 0 yield False.
>> so you can also
On Mon, 19 Sep 2005 12:16:15 +0200, sven wrote:
> to make sure that an operation yields a boolean value wrap a bool()
> around an expression.
> None, 0 and objects which's len is 0 yield False.
> so you can also do stuff like that:
Are there actually any usage cases for *needing* a Boolean value
At 02:20 19.09.2005, James H. wrote:
>Greetings! I'm new to Python and am struggling a little with "and" and
>"or" logic in Python. Since Python always ends up returning a value
>and this is a little different from C, the language I understand best
>(i.e. C returns non-zero as true, and zero as f
James H. wrote:
> Greetings! I'm new to Python and am struggling a little with "and" and
> "or" logic in Python. Since Python always ends up returning a value
> and this is a little different from C, the language I understand best
> (i.e. C returns non-zero as true, and zero as false), is there
James H. wrote:
> Greetings! I'm new to Python and am struggling a little with "and" and
> "or" logic in Python. Since Python always ends up returning a value
> and this is a little different from C, the language I understand best
> (i.e. C returns non-zero as true, and zero as false), is there a
22 matches
Mail list logo