int, float and string...

Shagshag13 shagshag13 at yahoo.fr
Tue Jun 4 10:48:48 CEST 2002


Still wondering questions about pythoner's way...

Why does i have :

>>> int('0.0123456789')
Traceback (most recent call last):
  File "<pyshell#157>", line 1, in ?
    int('0.0123456789')
ValueError: invalid literal for int(): 0.0123456789

The correct way to avoid is it :

>>> int(float('0.0123456789'))
0

???

And to check if a number should be use as an int rather than a float, can i use :

>>> int(float('0.0123456789')) == float('0.0123456789')
0
>>> int(float('5.00000000000009')) == float('5.00000000000009')
0
>>> int(float('5.0000000000000')) == float('5.0000000000000')
1

or i miss a better way  ???

By doing this kind of stuff do i save memory ?
(having a huge list of int and float, casting them to float only for math operations)

thanks,

s13.





More information about the Python-list mailing list