Typing \n in strings

Jeff Epler jepler at unpythonic.net
Sat Apr 3 22:13:37 EST 2004


>>> a = "line1\nline2"
>>> a                  # This prints repr(a)
'line1\nline2'
>>> print a            # This prints a
line1
line2

When you enter an expression in the interactive interpreter, and its
result is not None, Python shows you the repr() of the value.  When you
use 'print expression', you are shown the str() of the value.
Skip ahead to 7.1, "Fancier Output Formatting", for some more details.

Jeff




More information about the Python-list mailing list