这应该是一件简单的事情,但我找不到答案。我怎么能得到这个:
myList=["hello","nice","people"]
print(myList)
...写:
hello
nice
people
我可以删除括号或在单独的行中获取帖子,但不能同时删除两者。提前谢谢!
答案 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")