How do I convert a list into a string with spaces in Python?

前端 未结 6 1490
死守一世寂寞
死守一世寂寞 2020-12-04 22:54

How can I convert a list into a space-separated string in Python?

For example, I want to convert this list:

my_list = [how,are,you]

6条回答
  •  长情又很酷
    2020-12-04 23:30

    I'll throw this in as an alternative just for the heck of it, even though it's pretty much useless when compared to " ".join(my_list) for strings. For non-strings (such as an array of ints) this may be better:

    " ".join(str(item) for item in my_list)
    

提交回复
热议问题