Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Data Science by (18.4k points)

I need an explanation of why the output is A for the following code is.

a = True

print (('A','B')[a == False])

1 Answer

0 votes
by (36.8k points)

Assuming the first line is a = True, a == False evaluates to false, therefore the boolean value of 0. Therefore your expression is same as the print(('A', 'B')[0]) which prints 'A'

Do check out Python Data Science Course which helps you understand from scratch

Browse Categories

...