When I first started coding in Python more than a decade ago, one of the simplest things that tripped me up was printing text exactly the way I wanted.
I often needed to display a variable on one line and then move directly to the next line for clarity. At first, I didn’t realize how many different ways Python gives us to handle new lines.
In this tutorial, I’ll walk you through several easy methods I personally use to print a new line after a variable in Python.
Methods to Print a New Line After a Variable in Python
Let me explain to you the methods to print a new line after a variable in Python.
Method 1 – Use the Default Behavior of print()
By default, Python’s print() function ends with a newline character. So, if you print a variable, Python will automatically move to the next line.
# Example: Printing employee ID followed by a new line
employee_id = 4521
print(employee_id)
print("Record saved successfully.")Output:
4521
Record saved successfully.I executed the above example code and added the screenshot below.

This method shows that Python’s print() function automatically appends a newline at the end of each print statement.
Method 2 – Add \n Explicitly
Sometimes I prefer to add a newline character manually. This gives me control when I want to format text inline.
# Example: Printing sales amount with a newline
sales_amount = 1750
print("Total Sales: $" + str(sales_amount) + "\n")
print("Report generated.")Output:
Total Sales: $1750
Report generated.I executed the above example code and added the screenshot below.

This method demonstrates adding \n explicitly to control exactly where a newline appears in the output. It’s useful for custom formatting when you want precise placement of line breaks.
Method 3 – Use f-Strings
f-Strings, introduced in Python 3.6, provide a clean and efficient way to format strings. They allow embedding variables directly into strings using {} placeholders.
# Example: Printing city name with newline
city = "New York"
print(f"City: {city}\n")
print("Weather data updated.")Output:
City: New York
Weather data updated.I executed the above example code and added the screenshot below.

You can include \n within f-strings to easily control line breaks in your output. This method keeps your code concise, readable, and highly customizable.
Method 4 – Use the end Parameter in print()
The end parameter in print() lets you control what happens at the end of the output. By default, it’s \n. You can set it explicitly.
# Example: Printing student grade with newline
grade = "A"
print("Grade:", grade, end="\n")
print("Evaluation complete.")Output:
Grade: A
Evaluation complete.I executed the above example code and added the screenshot below.

Using the end=”\n” parameter in print() gives you explicit control over line breaks, making your output formatting more flexible.
Method 5 – Print Multiple Lines with Triple Quotes
If I want to print a variable and some text together across multiple lines, I use triple quotes.
# Example: Printing product details
product = "Laptop"
print(f"""
Product: {product}
Status: In Stock
""")Output:
Product: Laptop
Status: In StockUsing triple quotes allows printing clean, multi-line strings easily, keeping formatting exactly as written. It’s great for displaying structured output like reports or details.
Method 6 – Use os.linesep
os.linesep provides the correct newline character(s) based on the operating system, ensuring platform-independent formatting. It’s useful for cross-platform scripts where newline behavior differs.
import os
# Example: Printing employee name with system-specific newline
employee = "John Doe"
print("Employee Name: " + employee + os.linesep + "Attendance marked.")Output:
Employee Name: John Doe
Attendance marked.This method makes code portable by adapting to the system’s line-ending style. It’s best for generating files or outputs that must be OS-compatible.
Method 7 – Write to a File with New Lines
This method is helpful when you want to store output permanently instead of printing it on the console. It writes each entry on a new line in the file.
# Example: Writing customer IDs to a file
customer_ids = [101, 102, 103]
with open("customers.txt", "w") as file:
for cid in customer_ids:
file.write(str(cid) + "\n")It’s ideal for saving logs, reports, or structured data that can be accessed later.
Printing a new line after a variable in Python is simple once you know the options.
- If you just need the basics, rely on the default print().
- For more control, use \n, f-strings, or the end parameter.
- For cross-platform scripts, os.linesep is your friend.
I use these methods daily when formatting logs, reports, and console outputs. Try them out and see which one fits your workflow best.
You may read:
- Select Items from a List in Python
- Iterate Through a List in Python
- Merge Lists Without Duplicates in Python
- Python Lists of Floats

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.