带有列表的Python concat字符串 [英] Python concat string with list

查看:292
本文介绍了带有列表的Python concat字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从列表中构建一个字符串.

I wanted to build a string from a list.

我使用了string.join()命令,但是如果我有:

I used the string.join() command, but if I have :

['hello', 'good', 'morning']

我得到:hellogoodmorning

有没有一种方法可以让我在每个单词之间加一个空格? (无需编写for循环)

Is there a method that allows me to put a space between every word ? (without the need to write a for loop)

亲切的问候.

推荐答案

您需要做的就是在连接前面添加空格.

All you need to do is add the space in front of join.

 ' '.join(list)

这篇关于带有列表的Python concat字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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