Implicit conversion to boolean in if and while statements
rosuav at gmail.com
Sun Jul 15 10:47:05 CEST 2012
On Sun, Jul 15, 2012 at 6:34 PM, Andrew Berg <bahamutzero8825 at gmail.com> wrote:
> Converting 0 and 1 to False and True seems reasonable, but I don't see
> the point in converting other arbitrary values.
It's for convenience. Unfortunately, not all languages treat all types
the same way. It's very handy, though, to be able to use
if not foo: foo = some_initializer
when foo starts out as, say, None. Or . Or, in fact, any other "empty" value.
More information about the Python-list