没有括号蟒蛇打印数组中的单个行 [英] python print array without brackets in a single row
本文介绍了没有括号蟒蛇打印数组中的单个行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Python列表
例如:
名称= [山姆,彼得,詹姆斯,朱利安,安安]
我想打印在单行数组但不正常的,[]
名称= [山姆,彼得,詹姆斯,朱利安,安安]
打印(地名)
将给输出;
[山姆,彼得,詹姆斯,朱利安,安安]
这不是我想要的,而不是我的格式希望它是这样的;
山姆,彼得,詹姆斯,朱利安,安
请注意:必须在一行
。解决方案
打印','。加入(地名)
这,像它的声音,只是需要在列表中的所有元素,并加入他们,
。
I have a list in Python eg:
names = ["Sam", "Peter", "James", "Julian", "Ann"]
I want to print the array in a single line without the normal "" []
names = ["Sam", "Peter", "James", "Julian", "Ann"]
print (names)
will give the output as;
["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 ', '
.
这篇关于没有括号蟒蛇打印数组中的单个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文