您现在的位置是:课程教程文章

python中列表元素怎么转数字

2023-12-18 20:45课程教程文章 人已围观

本文实例讲述了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;

推荐学习《python教程》。

课程教程:python中列表元素怎么转数字

上一篇:如何进入python终端

下一篇:没有了

站点信息

  • 文章统计篇文章