Usecase of |= in python
I came across |= operator today in codebase and did not recognise it, and
searching google for python "|=" returns nothing useful for me.
Testing the outcome of operations below yields the following:
>>> from itertools import combinations
>>> def wtf_is_it(left, right):
>>> orig_left = left
>>> left |= right
>>> return '%s |= %s == %s ' % (orig_left, right, left)
>>> results = [wtf_is_it(l, r) for l, r in combinations(xrange(5), 2)]
>>> print '\n'.join(results)
0 |= 1 == 1
0 |= 2 == 2
0 |= 3 == 3
0 |= 4 == 4
1 |= 0 == 1
1 |= 2 == 3
1 |= 3 == 3
1 |= 4 == 5
2 |= 0 == 2
2 |= 1 == 3
2 |= 3 == 3
2 |= 4 == 6
3 |= 0 == 3
3 |= 1 == 3
3 |= 2 == 3
3 |= 4 == 7
4 |= 0 == 4
4 |= 1 == 5
4 |= 2 == 6
4 |= 3 == 7
Looks like it does an or and if the right side is greater than the left
then it adds the two together, otherwise it maintains the orig value?
What is the name of this operator and what is the value of it?
No comments:
Post a Comment