[Tutor] Stupid Pythony Newbie Question: Basic Operators;

Gregor Lingl gregor.lingl at aon.at
Sun Mar 16 11:45:40 CET 2008

```Michael Lim schrieb:
> with what the following 2 basic operators do in like simple english:
>
> 1.
>
> ^
This operator performs a logical operation, the exclusive or, also xor,
for the binary digits af two integer numbers. The operation will be
performed bitwise. You will understand this only if you know what the
binary  representation of a integer is. It goes like this:

xor of two digits 0 or 1 returns 1 if these are different and 0 else.

12    --->    '1100'        (which means 12 = 8 + 4)
9     --->    '1001'        (which means 9 = 8 + 1)
xor:    '0101'        so the result is 4 + 1 = 5

>>> 12 ^ 9
5
>>>

>
> 2.
> %
This is simpler: % returns the remainder you get if you perform an
integer division. Example 17 divided by 5 results in the quotient 3 and
the remainder 2.

>>> 17 % 5
2

If you want to know both, quotient and remainder, you can use the divmod
function:

>>> divmod(17,5)
(3, 2)

With best regards,
Gregor

> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
```