Re: Question About Logic In Python

2005-09-23 Thread Steve Holden
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

Re: Question About Logic In Python

2005-09-23 Thread Terry Hancock
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:

Re: Question About Logic In Python

2005-09-23 Thread Bryan Olson
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

Re: Question About Logic In Python

2005-09-22 Thread Steve Holden
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

Re: Question About Logic In Python

2005-09-22 Thread Ron Adam
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

Re: Question About Logic In Python

2005-09-22 Thread Terry Reedy
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,

Re: Question About Logic In Python

2005-09-22 Thread Terry Hancock
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

Re: Question About Logic In Python

2005-09-22 Thread Bengt Richter
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

Re: Question About Logic In Python

2005-09-22 Thread Ron Adam
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

Re: Question About Logic In Python

2005-09-21 Thread Steven D'Aprano
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),

Re: Question About Logic In Python

2005-09-21 Thread Steven D'Aprano
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

Re: Question About Logic In Python

2005-09-21 Thread Bengt Richter
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

Re: Question About Logic In Python

2005-09-21 Thread Terry Reedy
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

Re: Question About Logic In Python

2005-09-21 Thread Steven D'Aprano
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

Re: Question About Logic In Python

2005-09-21 Thread Ron Adam
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

Re: Question About Logic In Python

2005-09-19 Thread sven
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),

Re: Question About Logic In Python

2005-09-19 Thread Steven D'Aprano
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?

Re: Question About Logic In Python

2005-09-19 Thread Bengt Richter
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

Re: Question About Logic In Python

2005-09-19 Thread Ron Adam
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

Re: Question About Logic In Python

2005-09-18 Thread Dan Bishop
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

Re: Question About Logic In Python

2005-09-18 Thread [EMAIL PROTECTED]
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