您的当前位置:首页正文

python中列表元素怎么转数字

来源:花图问答

本文实例讲述了Python中列表元素转为数字的方法。分享给大家供大家参考,具体如下:

有一个数字字符的列表:

numbers = ['1', '5', '10', '8']

想要把每个元素转换为数字:

numbers = [1, 5, 10, 8]

用一个循环来解决:

new_numbers = [];
for n in numbers:
  new_numbers.append(int(n));
numbers = new_numbers;

推荐学习《》。