Python can't divide??!?!

Tim Peters tim.one at comcast.net
Thu Feb 5 23:33:55 EST 2004


[Gerrit]
> I think what confuses people is that the simple reprentation in the
> interactive shell calls repr(), not str(). If it would, like Ruby, it
> would be even more confusing:
>
> 19:22:38:0:gerrit at optiplex:~$ irb
> irb(main):003:0> v=0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1
> => 1
> irb(main):004:0> v
> => 1
> irb(main):005:0> v==1
> => false

Or like Python used to do -- repr(float) used to be the same as str(float).
A consequence of the change is that everyone gets acquainted with fp reality
early now, and in much the same shallows ways.  They *used* to get tripped
up later, in subtler ways, such as finding out after a day's debugging that
(e.g.) an if test on "v == 1" in your kind of example above failed "for no
good reason at all".  It's easier to explain why 0.1 doesn't display as 0.1
(because it's not 0.1, that's why <wink>).





More information about the Python-list mailing list