Warum ist es möglich, Boolesche Werte als Index in Python zu benutzen? zMit Boolesche Werte als Array-Index in Python
>>> a = [1, 2, 3, 4, 5]
>>> a[True]
2
>>> a[False]
1
Da Python eine stark typisierte Sprache ist, sollte der Compiler kein Typeerror werfen wie wenn eine Zeichenfolge und integer Addition? z.B.
>>> "1" + 1
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: cant convert 'int' object to 'str' implicitly
>>> 1 + "1"
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Boolesche Unterklasse ganzen Zahlen, wie man es von 'isinstance (True, int) sehen kann'. – jonrsharpe
http://stackoverflow.com/questions/2764017/is-false-0-and-true-1-in-python-a-implementation-detail-or-is-it-guarante –