Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65981
| From | Christopher Welborn <cjwelborn@live.com> |
|---|---|
| Subject | Re: Simple % question |
| Date | 2014-02-11 19:51 -0600 |
| References | <63EBCBF1-6C1B-4B8B-9D4A-0567CBDA978A@cox.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6718.1392169918.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Simple % question Christopher Welborn <cjwelborn@live.com> - 2014-02-11 19:51 -0600
csiph-web