Drossel
0
Q:

python join list to string

>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
2
# example of join() function in python

numList = ['1', '2', '3', '4']
separator = ', '
print(separator.join(numList))
15
# Python program to demonstrate the 
# use of join function to join list 
# elements with a character. 
  
list1 = ['1','2','3','4']  
  
s = "-"
  
# joins elements of list1 by '-' 
# and stores in sting s 
s = s.join(list1) 
  
# join use to join a list of 
# strings to a separator s 
print(s) 

OUTPUT:
  1-2-3-4
8
list = ['Add', 'Grepper', 'Answer']
Inline
> joined = " ".join(list)
> Add Grepper Answer
Variable
> seperator = ", "
> joined = seperator.join(list)
> Add, Grepper, Answer
7

New to Communities?

Join the community