如何使用 Python 将列表转换为字符串?
使用
''.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'
xs = ['L', 'O', 'L']
lol_string = ''.join(map(str, xs))