2011年12月25日星期日

what is remainder or modulus in python

http://stackoverflow.com/questions/509710/python-quotient-vs-remainder

Modulo is performed in the integer context, not fractional (remainders are integers). Therefore:
1 % 1  = 0  (1 times 1 plus 0)
1 % 2  = 1  (2 times 0 plus 1)
1 % 3  = 1  (3 times 0 plus 1)
6 % 3 = 0  (3 times 2 plus 0)
7 % 3 = 1  (3 times 2 plus 1)
8 % 3 = 2  (3 times 2 plus 2)
 
 

没有评论:

发表评论