+ 1

Why does this equal 5, from a python challenge

a=[4,5,6,7] Print(a[True] #output=5

12th Aug 2019, 12:01 PM
Lootus Maximus
Lootus Maximus - avatar
3 Antworten
+ 4
True = 1, False = 0, a[True] equivalent to a[1] That's how you got 5 as the output : )
12th Aug 2019, 12:03 PM
Ipang
+ 9
True is same 1 a[1] = 5
12th Aug 2019, 12:04 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 1
Nice i didn't realize that it counted as 1 thanks guys
12th Aug 2019, 12:06 PM
Lootus Maximus
Lootus Maximus - avatar