它只支持字符串,因为“.join()的输出将采用字符串格式:lista = [1,2,3,"hey","woot",2.44]
print (" ".join(map(str,lista)))
print type(" ".join(map(str,lista)))
1 2 3 hey woot 2.44
这是因为您不能附加int/float和string:
即)
^{pr2}$
完成连接后:lista = [1,2,3,"hey","woot",2.44]
print (" ".join(lista))
-
TypeError Traceback (most recent call last)
in ()
1 lista = [1,2,3,"hey","woot",2.44]
> 2 print (" ".join(lista))
3
TypeError: sequence item 0: expected string, int found
它声明索引0处的元素是int而不是字符串参数
在内部,join将遍历列表(iterable对象),并在本例中添加前缀" " a space,并提供一个字符串输出So finally "".join() does not support int/float