0
About union combine in python
print(5|3) how its output is 7, are there anyone to explain it, thanks
3 Respostas
+ 4
https://www.sololearn.com/learn/4073/?ref=app
5 has a binary value of "0101"
and 3 has a value of "0011"
+ 1
The operator you are using is bitwise OR.
It will change five into binary(101) and change 3 into its binary variant(11)
Then it will add the
101 + 11 = 111, which is 7 in decimal.
In bitwise OR 1 + 1 = 0, 1+0 = 1 and 0+0 = 0