Python按位分配运算符中的竖线
问题描述:
有一个代码,在类的方法中有一行:
There is a code and in class' method there is a line:
object.attribute |= variable
我不明白这是什么意思.我没有在基本的Python运算符列表中找到(| =).
I can't understand what it means. I didn't find (|=) in the list of basic Python operators.
答
这是带有赋值的bitwise or
.等同于
That is a bitwise or
with assignment. It is equivalent to
object.attribute = object.attribute | variable
在更多内容中阅读.