0
Why is the answer 2 ?
What is the output of this code ? def A(): print (a+1) def B () : print ( a-1) a=1 if a | 0 : ( i donot understand this line ) A() else : B()
2 ответов
+ 1
x | y - "bitwise or". Each bit of the output is 0 if the corresponding bit of x AND of y is 0, otherwise it's 1.
Example:
a = 10 = 1010 (Binary)
b = 4 = 0100 (Binary)
a | b = 1010 | 0100 = 1110 = 14 (Decimal)
0
| is a unary or operator
Binary of 1 = 1
Binary of 0 = 0
So 0 | 1 give 1 as a result which indicates true so function A() will be called