+ 2
Why is the answer zero for third line?
print(1 == 1 and 2 == 2) print(1 == 1 and 2 == 3) print((1 != 1 and 2 == 2)+(2 < 1 and 3 > 6))
6 odpowiedzi
+ 3
1 != 1 is false and its zero.
2 == 2 is true and its one.
It uses the and operator and since there is only one valid output, it outputs false,0.
2 < 1 is false and its zero.
3 > 6 is false and its zero.
It uses the and operator and since there are no valid outputs, it outputs false, 0.
Using the plus operator, 0 + 0 = 0.
+ 1
In Python boolean is subclass of integer type. So when you use the '+' operator with boolean, it implicitly converts them to integer type.
https://stackoverflow.com/questions/2406959/why-does-concatenating-a-boolean-value-return-an-integer
+ 1
That is because 'print False + False' gives you the value zero
0
James Clark I. Vinarao thanks for that explanation.
0
Avinesh thanks for the link I will look in to it.
0