Sometimes, we want to specify new lines on Python, when writing on files.
In this article, we’ll look at how to specify new lines on Python, when writing on files.
How to specify new lines on Python, when writing on files?
To specify new lines on Python, when writing on files, we can write the new line characters separately.
For instance, we write
file.write(line1)
file.write("n")
file.write(line2)
file.write("n")
file.write(line3)
file.write("n")
to call file.write
with the line1
, line2
, and line3
strings separated by newline characters.
file
is the file opened with open
with write permissions.
Conclusion
To specify new lines on Python, when writing on files, we can write the new line characters separately.