阿里巴巴测开编程题: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;

简单点

numbers = [ int(x) for x in numbers ]

 

posted @ 2021-01-25 22:03  蒋励  阅读(337)  评论(0编辑  收藏  举报