如何在Python中将列表转换为带空格的字符串? [英] How do I convert a list into a string with spaces in Python?

查看:739
本文介绍了如何在Python中将列表转换为带空格的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中将列表转换为以空格分隔的字符串?

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]

放入字符串"how are you"

空格很重要.到目前为止,我不想获得howareyou

The spaces are important. I don't want to get howareyou as I have with my attempt so far of using

"".join(my_list)

推荐答案

" ".join(my_list)

您需要使用空格而不是空字符串来连接...

you need to join with a space not an empty string ...

这篇关于如何在Python中将列表转换为带空格的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆