Sometimes, we want to print list elements on separate lines in Python.
In this article, we’ll look at how to print list elements on separate lines in Python.
How to print list elements on separate lines in Python?
To print list elements on separate lines in Python, we can call print
with the sep
argument.
For instance, we write
import sys
print(*sys.path, sep="n")
to call print
with the items in the sys.path
list as arguments with *
.
And then we set the sep
argument to n'
to use a new line as a separator after each item printed to print each entry in its own line.
Conclusion
To print list elements on separate lines in Python, we can call print
with the sep
argument.