Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65981 > unrolled thread

Re: Simple % question

Started byChristopher Welborn <cjwelborn@live.com>
First post2014-02-11 19:51 -0600
Last post2014-02-11 19:51 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Simple % question Christopher Welborn <cjwelborn@live.com> - 2014-02-11 19:51 -0600

#65981 — Re: Simple % question

FromChristopher Welborn <cjwelborn@live.com>
Date2014-02-11 19:51 -0600
SubjectRe: Simple % question
Message-ID<mailman.6718.1392169918.18130.python-list@python.org>
On 02/11/2014 07:06 PM, Scott W Dunning wrote:
> I just have a simple question.  I don’t understand why 1%10  = 1?
>
>
  I think because 1 is evenly divisible by 10 exactly 0 times with a 1
remainder. I mean int(1 / 10) == 0, with a 1 remainder.
The same is true for all numbers leading up to 10.

for i in range(12):
     print('{} % 10 == {}'.format(i, i % 10))

0 % 10 == 0
1 % 10 == 1
2 % 10 == 2
3 % 10 == 3
4 % 10 == 4
5 % 10 == 5
6 % 10 == 6
7 % 10 == 7
8 % 10 == 8
9 % 10 == 9
10 % 10 == 0
11 % 10 == 1

You can see that with the divmod() function also.



-- 
\¯\      /¯/\
  \ \/¯¯\/ / / Christopher Welborn (cj)
   \__/\__/ /  cjwelborn at live·com
    \__/\__/   http://welbornprod.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web