清理打印列表(python 3.3.3)

时间:2014-05-11 23:33:33

标签: python list printing output

这应该是一件简单的事情,但我找不到答案。我怎么能得到这个:

myList=["hello","nice","people"]
print(myList)

...写:

hello
nice
people

我可以删除括号或在单独的行中获取帖子,但不能同时删除两者。提前谢谢!

1 个答案:

答案 0 :(得分:1)

如果您使用print(splatting)并将函数的sep参数设置为换行符,

argument unpacking可以自行处理:

>>> myList = ["hello", "nice", "people"]
>>> print(*myList, sep="\n")
hello
nice
people
>>>

要进一步解释参数解包,请写下:

print(*["hello", "nice", "people"], sep="\n")

相当于写这个:

print("hello", "nice", "people", sep="\n")