To make a string have multiple lines you can use the% wrap character \n
. So:
string = 'uma linha\noutra linha'
print string
You can still use the os.linesep
function which according to the documentation it makes use of the most appropriate line break character for your operating system, in case Windows would be \r\n
.
string = 'uma linha%soutra linha' % os.linesep
print string
Result for any of the above two cases:
one line
other line
See working on Ideone .
Reference: Python Docs - linesep .
If you need to use several lines to form a string with a line you can do with \
:
string = '\
uma linha \
outra linha\
'
print string
Or with ()
:
string = ('uma linha '
'outra linha')
print string
Or even with ()
and +
.
string = ('uma linha ' +
'outra linha')
print string
Result for any of the above three cases:
one line another line
See working on Ideone .