如何将列表转换为字符串

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

3417212 次浏览

使用# 0:

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))