如何将列表转换为字符串[重复]

问题描述 投票:0回答:3

如何使用 Python 将列表转换为字符串?

python string list join
3个回答
2023
投票

使用

''.join

xs = ['1', '2', '3']
s = ''.join(xs)

如果列表包含整数,请在连接元素之前将元素转换为字符串:

xs = [1, 2, 3]
s = ''.join(str(x) for x in xs)

438
投票
>>> xs = [1, 2, 3]       
>>> " ".join(str(x) for x in xs)
'1 2 3'

136
投票
xs = ['L', 'O', 'L']
lol_string = ''.join(map(str, xs))
© www.soinside.com 2019 - 2024. All rights reserved.