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
uses of
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 for False, too:
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
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 logical operators work, but
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 aren't
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 (indexing,
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 if bools were
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 the number of
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 still stands. Could it be helpful if
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 subclass),
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 you
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 course if any of
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 questions
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 doesn't
understand how
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 odd
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 false),
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?
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 do stuff
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 usage cases for
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 anything
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
21 matches
Mail list logo