2007/2/19, Dick Moores <[EMAIL PROTECTED]>:
The docs list it at <http://docs.python.org/ref/augassign.html>, and send you to <http://docs.python.org/ref/primaries.html#primaries>, which seems a dead end. I've tried "^=" out a bit: >>> n = 5 >>> n ^= 8 >>> n 13 >>> n ^= 8 >>> n 5 >>> n ^= 8 >>> n 13 >>> n ^= 8 >>> n 5 and get that strange alternating behavior. Can someone explain? And while at it, please also explain "&=" and "|=".
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). So 5^8 = 110 ^ 1000 = 0110 ^ 1000 = 1110 = 13 and 13^8 = 1110 ^ 1000 = 0110 = 5 -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor