将列表中的所有字符串转换为int [英] Convert all strings in a list to int
本文介绍了将列表中的所有字符串转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python中,我想将列表中的所有字符串转换为整数。
In python, I want to convert all strings in a list to ints.
所以如果我有:
results = ['1', '2', '3']
如何制作:
results = [1, 2, 3]
推荐答案
使用map函数(在py2中):
Use the map function(in py2):
results = map(int, results)
在py3中:
results = list(map(int, results))
这篇关于将列表中的所有字符串转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文