+ 3
What is the out of this code? Why?
x, y=5, 0 test=x**y>0 QA=(0, 1)[test] print(QA)
2 Answers
+ 7
Because 5**0>0 evaluates to True, test get assigned to True.
In Python booleans work very similarly to integer values of 0 and 1 and can thus be used to index a list, or tuple in this case.
(0, 1)[True] equals (0, 1)[1], which evaluates to 1 and QA will equal 1.
+ 1
We know that anything power zero is one. So 5^0=1. Test=1>0=True