+ 1
What is the working of "|" operator in python..
asking as a learner because it is new to me.
2 odpowiedzi
0
The single "pipe" character "|" is the bitwise OR. It takes the bit/binary representation of the variables/literals that it is being used on and ORs their bits.
example:
x = 5 | 3;
bitwise 4 bit representation of these numbers "binary"
5 = 0101
3 = 0011
-------
| = 0111 = 7
When ORed, If either or both of the bits in that column = 1 then the result for that column = 1. If both bits in that column = 0 then the result for that column = 0.
There are also the bitwise AND "&", shift left "<<", shift right ">>", XOR "^", and the compliment "~" operators.
0
Or