-6

I have a list and a string below:

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

How can I concatenate them so I get (keeping in mind that the enum may change size) :

i like the following fruits: 

banana
apple
plum

I need the mystr in the starting and fruit names one by one as shown

Ebin Davis
  • 5,421
  • 3
  • 15
  • 20

1 Answers1

2

You can use str.format, and str.join to get your required output.

Ex:

fruits = ['banana', 'apple', 'plum']
mystr = 'i like the following fruits: \n\n{}'.format("\n".join(fruits))
print(mystr)

Output:

i like the following fruits: banana, apple, plum
Rakesh
  • 81,458
  • 17
  • 76
  • 113