1
>>> str4 = """This too
... is a multiline one
... built with triple double-quotes."""

>>> str4 #A
'This too\nis a multiline one\nbuilt with triple double-quotes.'

>>> print(str4) #B
This too
is a multiline one
built with triple double-quotes.

In #A and #B , we print str4 , first implicitly, then explicitly using the print function.

why the output are different.

deceze
  • 510,633
  • 85
  • 743
  • 889
Randy
  • 79
  • 6
  • 1
    Because just typing something into an interpreter, shows the result, not prints them. See how it's still quoted with `' '`. You can see all escape characters etc. that would be converted to their characters. It works only in interpreter. Basically, just typing something into an interpreted automatically does `repr(something)`, while `print` uses `str(something)` and prints the result (converts escape sequences). (`repr` and `str` are in most cases the same thing, but not in all) – h4z3 Jul 10 '19 at 08:29
  • In other words, it's the difference between the *representation* of a value, which is ideally valid source code, and program output explicitly produced by `print`. – deceze Jul 10 '19 at 08:31

0 Answers0