0
What is tais operator | ? Thanks for your help
i don't understand its fonction.
6 Respostas
+ 3
It is used for binary OR operation.
To understand better how it works, convert to numbers to binary.
For example, imagine 5 and 7:
decimal : 5 7
binary : 101 111
Then put one under the other and perform the operation each bit and the one above it:
101
111
---------------
111
resuming you get 0 only if both bits are zero.
This means that 5 | 7 = 7
+ 4
Since operators can be overloaded in Python, they are sometimes used for more than one purpose. E.g., besides binary OR (as Ulisses described) the pipe operator is also used for set union:
x = {1, 2}
y = {2, 3}
z = x | y
z is now equal {1, 2, 3}
+ 2
Thanks @Igor B for the 'sets' answer
0
In what language?
0
in python...
0
thanks a lot !