About union combine in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

About union combine in python

print(5|3) how its output is 7, are there anyone to explain it, thanks

8th Sep 2021, 11:39 AM
Nurgeldi Tuwakow
Nurgeldi Tuwakow - avatar
3 Answers
+ 4
https://www.sololearn.com/learn/4073/?ref=app 5 has a binary value of "0101" and 3 has a value of "0011"
8th Sep 2021, 11:41 AM
Abhay
Abhay - avatar
+ 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
8th Sep 2021, 11:43 AM
_Zi_
_Zi_ - avatar
+ 1
Thanks a lot Abhay , _Zi_ Your explanations are very useful
9th Oct 2021, 3:34 PM
Nurgeldi Tuwakow
Nurgeldi Tuwakow - avatar