Assignment Operators?
Chris Angelico
rosuav at gmail.com
Thu Oct 2 09:27:37 EDT 2014
On Thu, Oct 2, 2014 at 11:24 PM, Didymus <lynto28 at gmail.com> wrote:
>>>> errors = False
>>>> errors |= 3
>>>> errors
> 3
>>>> errors |= 4
>>>> errors
> 7
>
> The '|=' operator, I read should be like a = a | b, but this appears to add the two numbers as long as it's more than the previous:
>
>>>> errors |= 5
>>>> errors
> 7
It is indeed (mostly) equivalent to "a = a | b". Do you understand
what bitwise 'or' does?
When you use False there, it's equivalent to zero. Everything after
that is straight-forward bitwise or.
http://en.wikipedia.org/wiki/Bitwise_operation#OR
ChrisA
More information about the Python-list
mailing list