我想从列表中构建一个字符串.
我使用了string.join()命令,但如果我有:
['hello', 'good', 'morning']
Run Code Online (Sandbox Code Playgroud)
我明白了: hellogoodmorning
有没有一种方法可以让我在每个单词之间加一个空格?(无需编写for循环)
亲切的问候.
kev*_*kev 20
>>> ' '.join(['hello', 'good', 'morning'])
'hello good morning'
Run Code Online (Sandbox Code Playgroud)
加入字符串列表的标准和最佳方法.我想不出比这更好的东西.
This does what you want:
" ".join(['hello', 'good', 'morning'])
Run Code Online (Sandbox Code Playgroud)
Generally, when you are calling join() on some string you use " " to specify the separator between the list elements.
| 归档时间: |
|
| 查看次数: |
64936 次 |
| 最近记录: |