Hot to split string literals that will across two or more lines ?

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Nov 17 22:38:43 EST 2005


Xiao Jianfeng <fdu.xiaojf at gmail.com> wrote:
> I need to print a long sting, which is two long so it must expand
> two lines.

How is this string being constructed in the source? If it exists as a
single long string, why must it be so long?

Some techniques you may not be aware of:

    >>> chunks = ["abc", "def", "ghi"]
    >>> s = ''.join(chunks) 
    >>> print s
    abcdefghi

    >>> s = "#" * 10
    >>> print s
    ##########

You can, of course, modify the above so that they join or multiply to
create much longer strings.

-- 
 \                          "Everything is futile."  -- Marvin of Borg |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list