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

后端 未结 11 1991
北荒
北荒 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:20

    A more generic way to convert python lists to strings would be:

    >>> my_lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    >>> my_lst_str = ''.join(map(str, my_lst))
    >>> print(my_lst_str)
    '12345678910'
    

提交回复
热议问题