How to break a string across several lines but print as one line?
bokr at oz.net
Sat Aug 24 05:17:36 CEST 2002
On Fri, 23 Aug 2002 16:09:11 -0500, "Mark McEahern" <marklists at mceahern.com> wrote:
>> I have a very long string that I would like to be able
>> to break across several lines. However, I need the
>> string to print as one line. If I do something like
>> foo = '''your momma is sooooo fat that she
>> it prints as:
>> your momma is sooooo fat that she
>> I would like it as:
>> your momma is sooooo fat that she fooballs.
>The triple quote is designed for including newlines. So you need single
>quotes and the \ as shown below:
>Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
>[GCC 2.95.3-5 (cygwin special)] on cygwin
>Type "help", "copyright", "credits" or "license" for more information.
>>>> s = "Your momma"
>>>> s = "Your momma"\
>... "is quite fat"\
>... "and that's that."
>"Your mommais quite fatand that's that."
>>> s = ('Or, you can '
... 'take advantage of '
... 'newlines being ignored '
... 'in parenthesized expressions -- '
... 'and strings being concatenated '
... 'across whitespace.' )
'Or, you can take advantage of newlines being ignored in parenthesized expressions -- and
strings being concatenated across whitespace.'
(That line wrapped on output).
More information about the Python-list