【发布时间】:2016-06-23 03:05:58
【问题描述】:
def prepare_for_sort(st):
nums = str(st).split()
for each in nums:
each = int(each)
print(nums)
st 是数字为“20 50 4 8 4 64 6 47 8”的字符串。 Nums 必须是整数数组。为什么这不起作用?
【问题讨论】:
-
st似乎不是您期望的那样,因为"20 50 4 8 4 64 6 47 8"作为输入至少没有错误。仍然没有做你想做的事 -
即使您正确地将
nums放入整数列表中,您也不会返回来自prepare_for_sort的任何内容,因此您的所有工作都是徒劳的。
标签: python list for-loop type-conversion