+ 1
Query on python challenge question
I came across this question during a challenge. What does line 3 mean? a,b = 5,0 test = a**b > 0 ans = (0,1)[test] print(ans)
3 ответов
+ 5
test is a boolean, if a**b > 0, then test = True, if not, test = False
In this test case, a**b = 1, and 1>0, so test = True
Now to line 3, (0, 1)[test] is like saying (0, 1)[True], which is similar to saying (0, 1)[1], and this returns 1
So answer = 1
+ 1
Oh..so it's referring to index [1], I didn't think of that. Thanks
0
No problem 👌