Implicit conversion to boolean in if and while statements

Chris Angelico rosuav at
Mon Jul 16 08:00:06 CEST 2012

On Mon, Jul 16, 2012 at 3:03 PM, Ranting Rick
<rantingrickjohnson at> 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? Can you
> reduce this to the absurd? Or will you just choose to ignore this
> valid point?

Personally, I'm quite okay with automatic upcasts to string. But if
you want to be explicit, particularly with floats, the solution often
is not to use str(), but a proper number-formatting routine. You want
"String%f"%1.75 for full power.

But when you're just letting the language do the translation, it's
much of a muchness whether you put an explicit toString() call in.


More information about the Python-list mailing list