本文介绍了在单行中打印不带括号的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Python 列表例如
I have a list in Pythone.g.
names = ["Sam", "Peter", "James", "Julian", "Ann"]
我想在没有正常的[]
names = ["Sam", "Peter", "James", "Julian", "Ann"]
print (names)
将输出为;
["Sam", "Peter", "James", "Julian", "Ann"]
这不是我想要的格式,而是我希望它是这样的;
That is not the format I want instead I want it to be like this;
Sam, Peter, James, Julian, Ann
注意:它必须在一行中.
Note: It must be in a single row.
推荐答案
print(', '.join(names))
听起来,这只是将列表中的所有元素与 ', '
连接起来.
This, like it sounds, just takes all the elements of the list and joins them with ', '
.
这篇关于在单行中打印不带括号的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!