Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can add a trailing newline character to each element in the list before joining them using '\n'.join(my_list). Here's an example:

mylist = ["line 1", "line 2", "line 3"] mylistwithnewlines = [line + "\n" for line in mylist] text = ''.join(mylistwithnewlines)

This will add a newline character at the end of each line (except for the last one) and then join them using the '\n' separator.