bool constructor is inconsistent?

Stefan Behnel stefan_ml at behnel.de
Fri Sep 10 20:36:07 CEST 2010


Neal Becker, 10.09.2010 20:23:
> IN [3]: bool('False')
> Out[3]: True

Not inconsistent at all:

   >>> bool('false')
   True
   >>> bool('true')
   True
   >>> bool('')
   False
   >>> bool(32)
   True
   >>> bool(0)
   False

It simply follows Python's boolean coercion rules.

If you consider it inconsisten w.r.t. int('32'), then what about

    >>> list('[]')
    ['[', ']']

Stefan




More information about the Python-list mailing list