How to concatenate items in a list to a single string?

后端 未结 11 2005
北荒
北荒 2020-11-21 05:59

Is there a simpler way to concatenate string items in a list into a single string? Can I use the str.join() function?

E.g. this is the input [\'t

11条回答
  •  醉酒成梦
    2020-11-21 06:18

    If you want to generate a string of strings separated by commas in final result, you can use something like this:

    sentence = ['this','is','a','sentence']
    sentences_strings = "'" + "','".join(sentence) + "'"
    print (sentences_strings) # you will get "'this','is','a','sentence'"
    

    I hope this can help someone.

提交回复
热议问题