<br><br><div><span class="gmail_quote">2007/2/19, Dick Moores &lt;<a href="mailto:rdm@rcblue.com">rdm@rcblue.com</a>&gt;:</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 &lt;<a href="http://docs.python.org/ref/augassign.html">http://docs.python.org/ref/augassign.html</a>&gt;, and<br>send you to &lt;<a href="http://docs.python.org/ref/primaries.html#primaries">http://docs.python.org/ref/primaries.html#primaries
</a>&gt;,<br>which seems a dead end.<br><br>I&#39;ve tried &quot;^=&quot; out a bit:<br><br> &gt;&gt;&gt; n = 5<br> &gt;&gt;&gt; n ^= 8<br> &gt;&gt;&gt; n<br>13<br> &gt;&gt;&gt; n ^= 8<br> &gt;&gt;&gt; n<br>5<br> &gt;&gt;&gt; n ^= 8
<br> &gt;&gt;&gt; n<br>13<br> &gt;&gt;&gt; n ^= 8<br> &gt;&gt;&gt; n<br>5<br><br>and get that strange alternating behavior. Can someone explain?&nbsp;&nbsp;And<br>while at it, please also explain &quot;&amp;=&quot; and &quot;|=&quot;.
<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), &amp; of doing an and (1&amp;1 = 1, 1&amp;0=0&amp;1=0&amp;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&nbsp;&nbsp;--&nbsp;&nbsp;Skype: a_engels