使用map函數
list(map(int, numbers))
下面舉例冒泡排序
num = input("請輸入數字")
numbers = num.split(' ')
numbers = list(map(int, numbers))
for num in range(len(numbers)-1):
for i in range(num,len(numbers)):
if i < len(numbers)-1 and numbers[num] > numbers[i+1]:
numbers[num],numbers[i+1] = numbers[i+1],numbers[num]
print(numbers)
當然也可以自己迭代列表每個元素轉換為int()
