Python Print End Parameter

I have noticed that the smallest details often cause the most confusion for beginners. One of those details is how the Python print() function handles the end of a line. By default, every time you call the print function in Python, it moves to a new line.

This happens because of the end parameter, which hides quietly inside the function definition. I recall early in my career attempting to create a progress bar for a data migration script.

Every time my code updated the progress, it printed on a new line, cluttering the entire terminal window. In this tutorial, I will show you exactly how to manipulate this parameter to format your Python output.

The Default Behavior of Python Print

Before we make any changes, we need to understand what Python does under the hood.

When you use print(“Data”), Python actually executes print(“Data”, end=”\n”).

The \n is the character for a newline, which tells the terminal to jump down.

The Standard Newline Example

If I am processing a list of US states, notice how they appear:

# Standard Python print behavior
states = ["New York", "California", "Texas"]

for state in states:
    print(state)

In this case, Python prints “New York,” then moves to a line for “California,” and so on.

Method 1: Use Python End to Stay on the Same Line

Sometimes, you want to print multiple items on the same horizontal line. I often use this when I want to create a comma-separated list of values dynamically.

By setting the end parameter to a space or a comma, I tell Python not to jump to the next line.

Print US Cities on One Line

Here is how I would format a list of major US cities using a space as the end character:

# Using a space instead of a newline
cities = ["New York City", "Los Angeles", "Chicago", "Houston"]

print("Top US Cities:", end=" ")
for city in cities:
    print(city, end=" | ")

You can see the output in the screenshot below.

end python

When I run this, Python keeps everything on a single line, separated by the pipe character.

Method 2: Create a Custom Separator for Data Logs

In my experience building financial tools for US markets, formatting log files is crucial.

If I am logging stock prices for the S&P 500, I might want them separated by tabs for better readability.

Python makes this easy by allowing the \t (tab) character in the end parameter.

Example: Tab-Separated Stock Data

# Using tabs for alignment in Python
stocks = {"AAPL": 150.25, "MSFT": 310.40, "GOOGL": 2800.15}

print("Ticker", end="\t\t")
print("Price (USD)")

for ticker, price in stocks.items():
    print(ticker, end="\t\t")
    print(price)

You can see the output in the screenshot below.

end in python

By using end=”\t\t”, I create a clean, column-like structure in the terminal output.

Method 3: Remove the End Character Entirely

There are specific cases where you want no separation at all between your Python print statements.

I frequently use this when I am building a string character by character from a stream of data.

To do this, simply set the end parameter to an empty string "".

Example: Build a Serial Number String

# Concatenating output without spaces in Python
part_a = "USA"
part_b = "2025"
part_c = "99X"

print(part_a, end="")
print(part_b, end="")
print(part_c)

You can see the output in the screenshot below.

end= in python

The output will be USA202599X without any gaps or breaks.

Method 4: Implement a Real-Time Progress Bar

This is perhaps the most practical use of the Python end parameter I’ve encountered.

When I process large CSV files of US Census data, I want to see a progress bar that stays on one line. To do this, I use the carriage return character \r as the end value.

This tells the cursor to move back to the start of the current line rather than going to a new one.

Example: A Functional Progress Bar

import time

# Simulating a data process in Python
print("Processing US Census Data...", end="")

for i in range(1, 11):
    time.sleep(0.5)  # Simulating work
    # \r brings the cursor to the start of the line
    print(f"\rProgress: {i*10}% Complete", end="")

print("\nTask Finished!")

The \r character allows the current line to be overwritten, creating a smooth animation effect.

How Python End Differs from Python Sep

Many developers I mentor get confused between the end and sep parameters in Python. The sep (separator) parameter defines what goes between multiple objects in a single print call. The end parameter defines what goes after the entire print statement is finished.

Example: Compare Sep and End

# Demonstrating the difference in Python
print("Seattle", "Miami", "Boston", sep=", ", end=" --- End of List\n")

In this example, the comma and space go between the cities, while the dash goes at the very end.

Best Practices for Using Python Print End

Over the years, I have developed a few rules of thumb for using this feature effectively.

First, always remember to add a manual newline print() at the end of a loop if you used a custom end. If you don’t, your next line of code will start exactly where your loop left off, which looks messy.

Second, be careful with the flush parameter when using end. Sometimes, Python buffers the output, and your text might not appear until the buffer is full.

Setting flush=True ensures your text appears in the terminal instantly.

Example: Use Flush with End

# Ensuring instant output in Python
print("Loading Secure Connection...", end="", flush=True)
# The text appears immediately even without a newline

Common Mistakes to Avoid

One common mistake I see is forgetting that the end parameter must be a string. If you try to pass an integer or a list to the end argument, Python will throw a TypeError. Another mistake is overusing the carriage return \r.

While it works great in a standard terminal, some simple Python IDEs don’t handle it well and might display odd symbols. Always test your Python scripts in the actual environment where they will be used.

In this tutorial, I have covered several ways to use the end parameter in Python to control your output.

I hope you found this guide helpful and that it saves you time in your next Python project.

You may also like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.