in: my_tuple=('a',9,1,True,'a', [2,5])
in: my_tuple.index(1), my_tuple.index(True)
out: (2, 2)
can anyone explain what exactly is going on? Why index of the entry True and 1 are displayed the same?
in: my_tuple=('a',9,1,True,'a', [2,5])
in: my_tuple.index(1), my_tuple.index(True)
out: (2, 2)
can anyone explain what exactly is going on? Why index of the entry True and 1 are displayed the same?
Since True == 1
:
>>> 1 == True
True
>>> (1, True,).index(True)
0
bool
subclasses from int
in Python, and in Python 3.x, you will always have False = 0
and True = 1
.
>>> isinstance(True, int)
True
>>> int(True)
1