To make a string has multiple lines you can use the line break character \n
. Thus:
string = 'uma linha\noutra linha'
print string
You can still use the function os.linesep
which according to the documentation it makes use of the most appropriate line break character for your operating system, in case Windows would be the \r\n
.
string = 'uma linha%soutra linha' % os.linesep
print string
Result for either of the above two cases:
a line
other line
See it working on Ideone.
Reference: Python Docs - linesep.
If what you need is to use multiple 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 with ()
and the +
.
string = ('uma linha ' +
'outra linha')
print string
Result for any of the above three cases:
a line another line
See it working on Ideone.
Preferably, in an elegant way, and not like in javascript!
– Wallace Maxters