Possible Duplicate:
How can I convert a list to a string using Python?
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)
print ("\n".join(['I', 'would', 'expect', 'multiple', 'lines']))
Honeybear 2018-03-03 11:55
', '.join(list1)
to join the elements of the list with comma and whitespace or ' '.join(to)
to join with only white spac - R.S.K 2018-09-28 06:32
>>> L = [1,2,3]
>>> " ".join(str(x) for x in L)
'1 2 3'
L = ['L','O','L']
makeitastring = ''.join(map(str, L))
TypeError
exception,like this:
In [15]: L=['1','2','3']
TypeError Traceback (most recent call last)
TypeError: 'str' object is not callabl - wgzhao 2013-01-06 11:44
x = [1,2,3]
y = "'" + "','".join(map(str, x)) + "'"
tandy 2015-03-05 16:29
str(anything)
will convert any python object into its string representation. Similar to the output you get if you doprint(anything)
, but as a string - ToolmakerSteve 2016-01-27 20:17