Converting a string to integer/float

James Henderson james at logicalprogression.net
Thu Jan 22 06:37:19 EST 2004


On Thursday 22 January 2004 3:43 am, Ikot wrote:
> Hello,
> I am stuck with a problem, might be very trivial, to ask here, but
> dont find a way out. I read a string like 12345.678 from a text file,
> which will be string for me, but how do I convert it into a float for
> my use ?
> Thanks
> Ikot

float is a builtin type that can be constructed from a string:

>>> float('12345.678')
12345.678

You'd probably find it helpful to work your way through:

http://www.python.org/doc/current/lib/built-in-funcs.html

James
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/





More information about the Python-list mailing list