Pythonic way to print list items

后端 未结 11 1121
渐次进展
渐次进展 2020-11-22 10:29

I would like to know if there is a better way to print all objects in a Python list than this :

myList = [Person(\"Foo\"), Person(\"Bar\")]
print(\"\\n\".joi         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 11:16

    I think this is the most convenient if you just want to see the content in the list:

    myList = ['foo', 'bar']
    print('myList is %s' % str(myList))
    

    Simple, easy to read and can be used together with format string.

提交回复
热议问题