[issue21993] counterintuitive behavior of list.index with boolean values

Ezio Melotti report at bugs.python.org
Thu Jul 17 00:04:15 CEST 2014


Ezio Melotti added the comment:

'a' evaluates to true, but it's not equal to True:
  >>> bool('a')
  True
  >>> 'a' == True
  False
but 1 and True are equal (for historical reasons):
  >>> 1 == True
  True

Similarly '' evaluates to false, but it's not equal to False:
  >>> bool('')
  False
  >>> '' == False
  False
whereas 0 is equal to False:
  >>> 0 == False
  True

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21993>
_______________________________________


More information about the Python-bugs-list mailing list