将列表中的所有string转换为int
可能重复:
如何将string转换为Python中的整数?
如何将一个string列表转换为Python中的整数
在Python中,我想要将列表中的所有string转换为整数。
所以如果我有:
results = ['1', '2', '3'] 我如何做到这一点:
 results = [1, 2, 3] 
	
使用地图function(在py2中):
 results = map(int, results) 
在py3中:
 results = list(map(int, results)) 
使用列表理解:
 results = [int(i) for i in results] 
例如
 >>> results = ["1", "2", "3"] >>> results = [int(i) for i in results] >>> results [1, 2, 3]