0

This program doesn't work

print("test
test")

This runs as expected

print("""test
test""")

Is this simply because Python interpreter allows multi line strings for triple quotes, or there is some difference in the way it interprets the triple quotes?

nottoday
  • 9
  • 2
  • 1
    Python allows newlines in triple-quoted strings. That's what they are for, and why they're sometimes called multi-line string literals. – khelwood Jun 17 '20 at 10:38

2 Answers2

0

When You manually type \n it is interpreted as command to execute, you should use triple quotes to enter newlines(\n) manually.
Either """#Your string""" or '''#Your string'''

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
0

the triple quotes are also used to define multi line string that why ,

print("""test
test""")

the above code works,

You can also use the \ such as,

print("test \
test")

Have a look at this question-Pythonic way to create a long multi-line string

Prathamesh
  • 1,064
  • 1
  • 6
  • 16