Python a &= b meaning?

前端 未结 5 1402
萌比男神i
萌比男神i 2020-12-31 10:55

What does the &= operator mean in Python, and can you give me a working example?

I am trying to understand the __iand__ operator.

I just d

5条回答
  •  醉话见心
    2020-12-31 11:49

    It is a shorthand for:

    a = a & b
    

    & is bitwise and (see link for further explanation) if a and b are either int or long.

    Otherwise, the statement is equivalent to:

    a = a.__iand__(b)
    

    if __iand__ is defined for a.

提交回复
热议问题