Multi-line Strings

Kshitij Saraogi

Suppose, I want to define a two-line (or a multi-line) string.

I can do this in two ways:

  • Using escape sequence for the newline character.\n
    Ex: "This is the first sentence. \n This is the second sentence."
  • Using triple-quoted strings.
    Ex: """ This is the first sentence. This is the second sentence."""

Which is the more efficient or conventional ? Why ?

mike.k

I'm tempted to say it doesn't matter since each one still scans inside for escaped characters while parsing the text.

>>> print "a\n\tb"
a
        b
>>> print """a\n\tb"""
a
        b

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related