Olga Olga - 5 months ago 54
Python Question

Vertical bar in Python bitwise assignment operator

There is a code and in class' method there is a line:

object.attribute |= variable


I can't understand what it means. I didn't find (|=) in the list of basic Python operators.

Answer

That is a bitwise or with assignment. It is equivalent to

object.attribute = object.attribute | variable

Read more here.