turn list into string code example

Example 1: list to string python

list1 = [1, 2, 3]
str1 = ''.join(str(e) for e in list1)

Example 2: convert list to string python

# Python program to convert a list 
# to string using list comprehension 
   
s = ['I', 'want', 4, 'apples', 'and', 18, 'bananas'] 
  
# using list comprehension 
listToStr = ' '.join([str(elem) for elem in s]) 
  
print(listToStr)

Example 3: python list to string

mystring = 'hello, world'

mylist = string1.split(', ') #output => ['hello', 'world']

myjoin1 = ', '.join(mylist) #output => 'hello, world'
myjoin2 = ' '.join(mylist) #output => 'hello world'
myjoin3 = ','.join(mylist) #output => 'hello,world'

Example 4: convert list to string python

>>> mylist = ['spam', 'ham', 'eggs']
>>> print ', '.join(mylist)
spam, ham, eggs

Example 5: python list to string

By using ''.join

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