test_list=['1','3','2','6','8']print("Original list is: "+str(test_list))out_list=test_listfor i inrange(0,len(test_list)): out_list[i]=int(test_list[i])print("Out list is: "+str(out_list))
方法二:使用list的复合运算:
test_list=['1','3','2','6','8']print("Original list is: "+str(test_list))out_list=[int(i)for i in test_list]print("Out list is: "+str(out_list))
方法三: 使用map():
test_list=['1','3','2','6','8']print("Original list is: "+str(test_list))out_list=list(map(int,test_list))print("Out list is: "+str(out_list))
运算结果:
Original listis: ['1','3','2','6','8']Out listis: [1,3,2,6,8]