[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
2
 >>> -5%3
1
 >>>

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


-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list