Python concatenate string & list

前端 未结 5 1908
清酒与你
清酒与你 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:37

    You're going to have a problem if you name your variables the same as Python built-ins. Otherwise this would work:

    s = s + ', '.join([str(fruit) for fruit in fruits])
    

提交回复
热议问题