Next: String Literal Juxtaposition Up: String Literals Previous: Continuation Of String

Triple-quoted strings

In some cases, when you need to include really long strings (e.g. containing several paragraphs of informational text), it is annoying that you have to terminate each line with \n\, especially if you would like to reformat the text occasionally with a powerful text editor like Emacs. For such situations, ``triple-quoted'' strings can be used, e.g.


        hello = """

            This string is bounded by triple double quotes (3 times ").
        Newlines in the string are retained, though \
        it is still possible\nto use all normal escape sequences.

            Whitespace at the beginning of a line is
        significant.  If you need to include three opening quotes
        you have to escape at least one of them, e.g. \""".

            This string ends in a newline.
        """

Note that there is no semantic difference between strings quoted with single quotes (') or double quotes (").


guido@cwi.nl