A funnily inconsistent behavior of int and float
Grant Edwards
grante at visi.com
Sun Apr 6 14:55:22 EDT 2008
On 2008-04-06, Lie <Lie.1296 at gmail.com> wrote:
> I've noticed some oddly inconsistent behavior with int and float:
>
> Python 2.5.1 (r251:54863, Mar 7 2008, 03:39:23)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
>>>> int('- 345')
> -345
>
> works,
IMO, it oughtn't.
>>>> float('- 345.083')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: invalid literal for float(): - 345.083
That's the behavior I'd expect.
> The problem seems to be that float can't accept spaces between
> the sign and the number while int can. Possibly caused by some
> missing regex statement. Minor and harmless (most of the
> time), but should be made known.
--
Grant Edwards grante Yow! ... I live in a
at FUR-LINE FALLOUT SHELTER
visi.com
More information about the Python-list
mailing list