How to Print a New Line After a Variable in Python?

Estimated read time 1 min read

To print a new line after a variable in Python, you can use the escape character \n after the variable in the print() function. Here’s an example:

name = "John"

print(name + "\n")

This will print the variable name on one line, followed by a new line character on the next line:

John

Alternatively, you can use formatted strings (f-strings) to insert the variable value and the newline character:

name = "John"

print(f"{name}\n")

This will produce the same output as before.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply