Python-将列表中的所有字符串转换为int
在Python中,我想将列表中的所有字符串转换为整数。
所以,如果我有:
results = ['1', '2', '3']我该如何做:
results = [1, 2, 3]回答:
使用map功能(在Python 2.x中):
results = map(int, results)在Python 3中,您需要将结果从map转换为列表:
results = list(map(int, results))以上是 Python-将列表中的所有字符串转换为int 的全部内容, 来源链接: utcz.com/qa/432362.html

