Python concatenate string & list

前端 未结 5 1911
清酒与你
清酒与你 2020-12-14 08:08

I have a list and string:

fruits = [\'banana\', \'apple\', \'plum\']
mystr = \'i like the following fruits: \'

How can I concatenate them s

5条回答
  •  眼角桃花
    2020-12-14 08:30

    You can use this code,

    fruits = ['banana', 'apple', 'plum', 'pineapple', 'cherry']
    mystr = 'i like the following fruits: '
    print (mystr + ', '.join(fruits))
    

    The above code will return the output as below:

    i like the following fruits: banana, apple, plum, pineapple, cherry
    

提交回复
热议问题