How to convert list to string

Nm3 picture Nm3 · Apr 11, 2011 · Viewed 2.6M times · Source

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

Answer

Senthil Kumaran picture Senthil Kumaran · Apr 11, 2011

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)