<br><br><div><span class="gmail_quote">2007/2/19, Dick Moores <<a href="mailto:rdm@rcblue.com">rdm@rcblue.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The docs list it at <<a href="http://docs.python.org/ref/augassign.html">http://docs.python.org/ref/augassign.html</a>>, and<br>send you to <<a href="http://docs.python.org/ref/primaries.html#primaries">http://docs.python.org/ref/primaries.html#primaries
</a>>,<br>which seems a dead end.<br><br>I've tried "^=" out a bit:<br><br> >>> n = 5<br> >>> n ^= 8<br> >>> n<br>13<br> >>> n ^= 8<br> >>> n<br>5<br> >>> n ^= 8
<br> >>> n<br>13<br> >>> n ^= 8<br> >>> n<br>5<br><br>and get that strange alternating behavior. Can someone explain? And<br>while at it, please also explain "&=" and "|=".
<br></blockquote></div><br>To understand these operators, you will have to think of the numbers as binary numbers. Look at the digits. For two numbers x and y, x^y is the effect of doing an exclusive or on all digits (that is, 0^1 = 1^0 = 1 and 0^0 = 1^1 = 0), & of doing an and (1&1 = 1, 1&0=0&1=0&0=0) and | is an or on all digits (1|1=1|0=0|1 = 1, 0|0 = 0).
<br><br>So 5^8 = 110 ^ 1000 = 0110 ^ 1000 = 1110 = 13<br>and 13^8 = 1110 ^ 1000 = 0110 = 5<br><br><br clear="all"><br>-- <br>Andre Engels, <a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a><br>ICQ: 6260644 -- Skype: a_engels