Print['a','b'][True] returning b, why?

python

#1

Please help me to understand, why below code is returning b as a output.

print [‘a’,‘b’][True]

Thanks
Satish


#2

Good question @Satish, decode the above code as:

print[‘a’,‘b’][True]
print[‘a’,‘b’][1] # True represents 1 and False 0.

Hope, now you get the answer.

Regards,
Sunil