将列表中的所有字符串转换为int [英] Convert all strings in a list to int

查看:1550
本文介绍了将列表中的所有字符串转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在python中将字符串转换为整数?

如何在python中将字符串列表转换为整数

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆