How to break a string across several lines but print as one line?

Mark McEahern marklists at mceahern.com
Fri Aug 23 17:09:11 EDT 2002


[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

-





More information about the Python-list mailing list