[Tutor] string to int or float
jim_938 at hotmail.com
Mon Nov 3 07:15:58 EST 2003
I want to convert a list of strings to list of integers:
List = ['207','-308','-8.0','6']
and i want it like this
list = [207, -308, -8.0, 6]
i am trying to do it with int and float functions
But i dont know how i can check whether the string will be for float
function or int function.
for i in range(len(list)):
t = int(list[i])
But this will give error when it will encounter '-8.0' as it should be
submitted to float()
Is there any pythonic way to check whether i should use int or float.
Thanks in advance.
Nutrition is in! Junk food is out!
http://server1.msn.co.in/features/fabmall/ Be a part of the microwave
More information about the Tutor