osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple % question


On Wed, Feb 12, 2014 at 2:30 PM, Scott W Dunning <swdunning at cox.net> wrote:
> On Feb 11, 2014, at 6:36 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>> The real question is: What do you expect that symbol to mean?
>>
>> Its actual meaning is quite simple. In long division, dividing one
>> number by another looks like this:
>
> Yeah I understand what the % means.  It just confused me that 1%10 was 1.  In my thought process it just didn?t work.  1/10= .1 and I just didn?t see where the remainder of 1 came in.
>

Ah, yes. When Python 2 -> Python 3 changed the meaning of / the
meaning of % got tied instead to //. But if you think about it, with
the floating-point result you're describing there, it simply makes no
sense to even ask what the remainder is. So, if you're going to use %,
use //, and then it all makes sense.

ChrisA