Print list without brackets in a single row

前端 未结 12 1423
北恋
北恋 2020-11-22 17:01

I have a list in Python e.g.

names = [\"Sam\", \"Peter\", \"James\", \"Julian\", \"Ann\"]

I want to print the array in a single line withou

12条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 17:52

    Here is a simple one.

    names = ["Sam", "Peter", "James", "Julian", "Ann"]
    print(*names, sep=", ")
    

    the star unpacks the list and return every element in the list.

提交回复
热议问题