Implicit conversion to boolean in if and while statements
wuwei23 at gmail.com
Mon Jul 16 09:27:18 CEST 2012
On Jul 16, 3:03 pm, Ranting Rick <rantingrickjohn... at gmail.com> wrote:
> But if you are going to argue that "if obj" is *explicit enough*, then
> apply your argument consistently to "String"+1.75 also. Why must we be
> explicit about string conversion BUT not boolean conversion?
What _other_ than booleans can you expect a condition to reduce down
to? Seriously. What might you possibly expect 'obj' in 'if obj' to be?
Tuesday? The colour mauve? That sinking feeling that you're entering
into a debate that's far above your ability to understand it?
Now: as an expression "String"+1.75 can be _anywhere_, so _what_ you
want will very much be contextual. Do you want "String1.75"? Do you
want float("String") + 1.75? Do you want it to error? So yes, here you
very much need to be explicit.
> Can you reduce this to the absurd?
You've already taken care of that.
More information about the Python-list