小编hab*_*ant的帖子

.join() 返回列表作为 python 中的结果

请有人解释一下为什么 .join() 的行为如下:

input = [1, 0, 5, 3, 4, 12, 19]
a = " ".join(str(input))
print(a)
Run Code Online (Sandbox Code Playgroud)

结果是:

[ 1 ,   0 ,   5 ,   3 ,   4 ,   1 2 ,   1 9 ]
Run Code Online (Sandbox Code Playgroud)

不仅还有一个列表,而且还多了一个空间。怎么会?当我使用 map() 时它可以工作:

a = " ".join(list(map(str, input)))
Run Code Online (Sandbox Code Playgroud)

但我想知道我正在使用的 .join 方法有什么问题。

python string integer list

2
推荐指数
1
解决办法
96
查看次数

标签 统计

integer ×1

list ×1

python ×1

string ×1