Question About Logic In Python

S

Steve Holden

Terry said:
Except for counting the number of true values. This and other legitimate
uses of False/True as 0/1 (indexing, for instance) were explicitly
considered as *features* of the current design when it was entered. The
design was not merely based on backwards compatibility, but also on
actually use cases which Guido did not want to disable. There was lots of
discussion on c.l.p.
Sure. Perhaps I should have said it makes absolutely no sense "to expect
the results of aritmetic operations on bools to themselves be bools".
Sheesh, you have to be so careful nowadays ... :)

regards
Steve
 
T

Terry Hancock

Only because True is the last value here. ;-)

Nope, works for False, too:
False

I see what you mean, but if you were mixing types, then
you probably wanted the "value preserved" behavior. If
both objects are bool, the result is too (even if this
is only a coincidence, it still happens to be true).

So this still makes sense:
1

Effectively, what you'd be asking for is to have bool
coerce more strongly than ints or other types, so that
results would become boolean if any boolean argument
existed. But that would be a pretty major change in Python,
and break lots of code.
 
B

Bryan Olson

Steven said:
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 values is to give 'not' something
sensible to return.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,005
Latest member
ChasityFan

Latest Threads

Top