+ 2
A Why & how question
def f (m,n) return m|n print (f(10,20) why it is 30 ? how does it work ?
2 odpowiedzi
+ 11
Just in case you didn't get @Petr Leliaev's explanation:
Binary OR operation is performed based on the two numbers passed into the function. The two numbers are evaluated in binary format.
OR
0|0 = 0
0|1 = 1
1|0 = 1
1|1 = 1
10 (decimal) is 1010 (binary).
20 (decimal) is 10100 (binary).
01010
10100
----------
11110 = 30
----------
+ 3
m=10=1010(2)
n=20=10100(2)
m|n = 11110(2)=30(10)