int('2.1') does not work while int(float('2.1')) does
Joe Mason
joe at notcharles.ca
Mon Apr 5 23:47:03 EDT 2004
In article <40722555.66C70D40 at alcyone.com>, Erik Max Francis wrote:
> There's a fundamental difference between an int and a float. If the
> string you're trying to convert looks like a float, that means it
> doesn't look like an int.
>
> With your first example of '2.1', what should it mean? Should it
> truncate, round to negative infinity round to positive infinity, round
> to zero, what? Python can't guess for you, so it shouldn't try. Thus
> it's an error.
Why can it make this guess for "int(2.1)", then? It's got a rule for
converting floats to ints - why not use it here?
Joe
More information about the Python-list
mailing list