r/pythonhelp • • Dec 26 '19

Beginner help with print command with multiple variables

What is the proper way for print(message0, message1, message2, message3,) to have each variable on the next line?

I have tried doing '\n' before and after each variable and only get a syntax error. I have also tried doing ,'\n\n\n\n', as I saw on another forum, and that did not work out.

3 Upvotes

4 comments sorted by

3

u/xelf Dec 27 '19 edited Dec 27 '19
for x in (message0, message1, message2, message3):
    print(x)

or

print(f"{message0}\n{message1}\n{message2}\n{message3}")

or

print(message0 + '\n' + message1 + '\n' + message2 + '\n' + message3)

Or simply:

print(message0)
print(message1)
print(message2)
print(message3)

1

u/the-bid-d Dec 26 '19

If the /n doesn't work, I found

(''' Whatever message you're trying to say ''')

1

u/sentles Dec 27 '19

Either one of the ways suggested, or print("{}\n{}\n{}\n{}".format(message0, ...).

Also note that \n should be inside a string, or you'll get the SyntaxError.

1

u/Mezzomaniac Dec 27 '19

print(a, b, c, d, sep=ā€˜\n’)