如何使用Python将列表转换为字符串?
用:''.join
''.join
xs = ['1', '2', '3'] s = ''.join(xs)
如果列表包含整数,请在联接元素之前将元素转换为字符串:
xs = [1, 2, 3] s = ''.join(str(x) for x in xs)
>>> xs = [1, 2, 3] >>> " ".join(str(x) for x in xs) '1 2 3'