Implicit conversion to boolean in if and while statements

Albert van der Horst albert at spenarnc.xs4all.nl
Mon Jul 16 19:57:45 CEST 2012


In article <b2971c4d-0769-4d03-a7b6-c527629a85c1 at x39g2000yqx.googlegroups.com>,
Ranting Rick  <rantingrickjohnson at gmail.com> wrote:

>We DON'T want Python to silently convert "cost" to a string. What we
>DO want is to force the author to use the str function thereby making
>the conversion explicit.

We do want Python to silently convert "cost" to a string in the
proper context.

cost= 3.75
print( cost )

>
>Same with converting objects to bools.

I think "if" is sufficient context to convert something to a boolean.
It now is a matter of good taste and what fits best in Python as a
whole. Nothing to be dogmatic about.

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list