2024-04-26 19:00:14 发布
网友
这是我在编辑器上编辑并在shell上编译的代码。 如果我输入整数19,当我打印出c时,它仍然是['1','9'],而不是我想要的[1,9]。我在交互式解释器上尝试了这一点,而不是编译python文件,它起到了作用。在
['1','9']
[1,9]
a = raw_input("Please enter a positive number ") c = [] c = list(a) map(int, c)
您需要将map输出重新分配给c,因为它没有就位
map
c
>>> a=raw_input("Please enter a positive number ") Please enter a positive number 19 >>> c = list(a) >>> c = map(int,c) # use the list() function if you are using Py3 >>> c [1, 9]
参见docs on ^{}
Apply function to every item of iterable and return a list of the results.
(重点是我的)
您需要将
map
输出重新分配给c
,因为它没有就位参见docs on ^{}
(重点是我的)
相关问题 更多 >
编程相关推荐