Print list without brackets in a single row

前端 未结 12 1160
北恋
北恋 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:51

    You need to loop through the list and use end=" "to keep it on one line

    names = ["Sam", "Peter", "James", "Julian", "Ann"]
        index=0
        for name in names:
            print(names[index], end=", ")
            index += 1
    

提交回复
热议问题