Can any explain how it works ?? Ans is 3. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can any explain how it works ?? Ans is 3.

a =[1,3,6,7] print (a[True])

17th May 2020, 3:53 PM
Ravi Kumar Verma
Ravi Kumar Verma - avatar
6 Answers
+ 3
Ravi Kumar Verma Bhai, By default True and False are associated with Binary, Where: False means 0 and True means 1 So when you used True as index for the list, it automatically used 1 instead of True hence showing you element at Index 1 i.e Value = 3 :) Hope you Got it Ask ur doubts if u still have any
17th May 2020, 4:30 PM
Kanishk Mewal
Kanishk Mewal - avatar
+ 2
Ravi Kumar Verma true= 1, so a[true]=a[1] a[0]=1, a[1]=3,a[2]=6 etc.. a[false]=1
17th May 2020, 4:02 PM
Petr
+ 2
Petr Infinity @Kiibo Ghayal Thank you soo much.i understand now.
17th May 2020, 4:14 PM
Ravi Kumar Verma
Ravi Kumar Verma - avatar
+ 2
Kanishk Mewal thanks broo
17th May 2020, 5:51 PM
Ravi Kumar Verma
Ravi Kumar Verma - avatar
+ 1
True is equivalent to 1 False is equivalent to 0 a[True] = a[1] = 3 >>> Infinity
17th May 2020, 4:01 PM
Infinity
Infinity - avatar
- 1
since True == 1
17th May 2020, 4:24 PM
Aravind Shetty
Aravind Shetty - avatar