[Tutor] x%2

bob gailer bgailer at gmail.com
Tue Jan 10 21:53:37 CET 2012

On 1/10/2012 1:47 PM, Noah Hall wrote:
> a % b is the remainder operator. It returns what's "left" after 
> dividing a by b. 
Not to beat a dead horse- but % is the modulo operator.

It returns the residue class of the 2 operands. When a is positive this 
is the same as remainder, but not so for negative a.

 >>> 5%3
 >>> -5%3

FWIW the Python documentation (at least as of 2.7.2 has this wrong!)

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list