1

I had been trying to do it like when I add a new line to a normal statement but it doesn't work if I do it like that.

cars = ["audi", "bmw", "toyota"]
print(\ncars)

It shows this error:

SyntaxError: unexpected character after line continuation character

How does one add a new line to a printed list? Btw I am a beginner to python and programming in general.

  • 1
    `print(cars)` should do, and it automatically adds a newline. Also look at the documentation of [print()](https://docs.python.org/3/library/functions.html#print) – Devesh Kumar Singh Dec 28 '19 at 16:05
  • 1
    print("\n".join(cars)) This was answered already here: https://stackoverflow.com/questions/6167731/printing-list-elements-on-separated-lines-in-python – Atenean1 Dec 28 '19 at 16:17
  • It's not clear what you want to achieve. Are you trying to print each element of the list on a single line? – Riccardo Bucco Dec 28 '19 at 16:34
  • Riccardo Bucco No. I just wanted there to be a new line before the printed list. – Jaber Haisan Dec 28 '19 at 16:49

3 Answers3

5

try this:

print("\n",cars)

write backslash n, instead of slash n

Negar37
  • 352
  • 1
  • 8
0

print("\n".join(cars))

This was answered already here:

Printing list elements on separated lines in Python

Atenean1
  • 82
  • 11
-2

Try

print("\n"+cars)

That's the correct way to do it. You need to write backslash n, not forward slash n

Akshath Mahajan
  • 248
  • 2
  • 11