如何将列表中的值类型从字符串更改为整数

new*_*ang 0 python integer list

我想将值转换list_a为整数。

list_a = ['20.3', '35', '10', '6.74', '323']

for i in list_a:
    print int(i) * 10
Run Code Online (Sandbox Code Playgroud)

Nil*_*jan 5

使用地图。使用Python2:

>>> list_a = ['20.3', '35', '10', '6.74', '323']
>>> list_a = map(float, list_a)
>>> list_a[0]*2
40.6
Run Code Online (Sandbox Code Playgroud)

在Python3中,map返回一个迭代器而不是列表。所以,对于 Python3:

>>> list_a = list( map(float, list_a) )
Run Code Online (Sandbox Code Playgroud)