How to break a string across several lines but print as one line?
Bengt Richter
bokr at oz.net
Fri Aug 23 23:17:36 EDT 2002
On Fri, 23 Aug 2002 16:09:11 -0500, "Mark McEahern" <marklists at mceahern.com> wrote:
>[Derek Basch]
>> 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
>> this:
>>
>> foo = '''your momma is sooooo fat that she
>> fooballs.'''
>>
>> it prints as:
>>
>> your momma is sooooo fat that she
>> fooballs.
>>
>> 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
>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."
>>>> s
>"Your mommais quite fatand that's that."
>>>>
>
>// m
>
>-
>
>
>>> s = ('Or, you can '
... 'take advantage of '
... 'newlines being ignored '
... 'in parenthesized expressions -- '
... 'and strings being concatenated '
... 'across whitespace.' )
>>> s
'Or, you can take advantage of newlines being ignored in parenthesized expressions -- and
strings being concatenated across whitespace.'
(That line wrapped on output).
Regards,
Bengt Richter
More information about the Python-list
mailing list