945
votes

How can I convert a list to a string using Python?

3
str(anything) will convert any python object into its string representation. Similar to the output you get if you do print(anything), but as a string. - ToolmakerSteve
So one way to make this different than that one is to suggest using json to do it like stackoverflow.com/questions/17796446/…. Using json easily allows the reverse process (string to list) to take place. But the OP really did need to explain themselves. Is it for display only or some other purpose? - demongolem
Please give an example of the format you want. - Solomon Ucko

3 Answers

1592
votes

By using ''.join

list1 = ['1', '2', '3']
str1 = ''.join(list1)

Or if the list is of integers, convert the elements before joining them.

list1 = [1, 2, 3]
str1 = ''.join(str(e) for e in list1)
361
votes
>>> L = [1,2,3]       
>>> " ".join(str(x) for x in L)
'1 2 3'
108
votes
L = ['L','O','L']
makeitastring = ''.join(map(str, L))