0

What is tais operator | ? Thanks for your help

i don't understand its fonction.

31st May 2017, 11:28 PM
kardak
6 odpowiedzi
+ 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
31st May 2017, 11:50 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 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}
1st Jun 2017, 12:01 AM
Igor B
Igor B - avatar
+ 2
Thanks @Igor B for the 'sets' answer
1st Jun 2017, 12:53 AM
Kirk Schafer
Kirk Schafer - avatar
0
In what language?
31st May 2017, 11:42 PM
Igor B
Igor B - avatar
0
in python...
31st May 2017, 11:45 PM
kardak
0
thanks a lot !
1st Jun 2017, 4:33 AM
kardak