[Tutor] string to int or float

Alan Gauld alan.gauld at blueyonder.co.uk
Mon Nov 3 14:40:14 EST 2003

> List = ['207','-308','-8.0','6']
> and i want it like this
> list = [207, -308, -8.0, 6]

Depending on whether you trust your source of raw data this 
might be one place where I'd use eval():

list = map(eval,List)

But if the strings are potentially unsecure then I'd use one 
of the other methods suggested already.

Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list