2011-10-28 51 views

回答

4

這裏有一種方法:

myList = [ "1", "2", "3" ] 
myList = [ int(i) for i in myList ] 
1

["1", "2", "3"][1, 2, 3]都是列表。前者只是一個字符串列表,而後者是一個整數列表。每一個元素調用int將其轉換爲整數,如:

str_list = ["1", "2", "3"] 
int_list = [int(e) for e in str_list] 
# or ... 
int_list = map(int, str_list) 
0

如果陣列是真的[ 「1」 「2」 「3」],它將被串聯成一個像這樣[[123]]的單個字符串,因此您需要像這樣拆分字符串:

newList = [] 
for n in xrange(len(oldList[0])): 
    newList.append(int(oldList[0][n]))