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
OP's question is: does something like following exists, if not then why
print(p) for p in myList # doesn't work, OP's intuition
answer is, it does exist which is:
[p for p in myList] #works perfectly
Basically, use []
for list comprehension and get rid of print
to avoiding printing None
. To see why print
prints None
see this