How to Print Multiple Variables on Separate Lines in Python?

Estimated read time 1 min read

To print multiple variables on separate lines in Python, you can use the print() function and separate the variables with commas. You can also use the escape character \n to print each variable on a separate line. Here’s an example:

name = "John"
age = 35
height = 1.85

print(name, "\n", age, "\n", height)

This will print each variable on a separate line:

John
35
1.85

Alternatively, you can use f-strings (formatted strings) to format the output and use the newline character to separate the lines:

name = "John"
age = 35
height = 1.85

print(f"{name}\n{age}\n{height}")

This will produce the same output as before.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply