[Tutor] Strange range and round behaviour

Adam Bark adam.jtm30 at gmail.com
Mon Jun 7 20:20:22 CEST 2010


Just out of curiosity does anyone know why you get a deprecation warning if
you pass a float to range but if you use round, which returns a float, there
is no warning?

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> range(2.0)
__main__:1: DeprecationWarning: integer argument expected, got float
[0, 1]
>>> range(round(2.0))
[0, 1]
>>> round(2.0)
2.0
>>> round(2.0, 0)
2.0
>>> round.__doc__
'round(number[, ndigits]) -> floating point number\n\nRound a number to a
given
precision in decimal digits (default 0 digits).\nThis always returns a
floating
point number.  Precision may be negative.'
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100607/b9cf27a4/attachment.html>


More information about the Tutor mailing list