list = ['first', 'second', 'third', 'fourth']
s = '/'
newList = s.join(list)
print(newList)
This code outputs
"first/second/third/fourth"
list = ['first', 'second', 'third', 'fourth']
s = '/'
newList = s.join(str(list))
print(newList)
This code outputs
"[/'/f/i/r/s/t/'/,/ /'/s/e/c/o/n/d/'/,/ /'/t/h/i/r/d/'/,/ /'/f/o/u/r/t/h/'/]"
What does str()
do here that causes the list to separate by every letter?
The
str()
create a string like"['first', 'second', 'third', 'fourth']"
.And
s.join()
treat the string as a char array. Then it put'/'
between every element in the array.