How to Print in Same Line in Python?

When I first started working with Python, one of the things that confused me was how to print multiple values on the same line.

By default, Python prints output on separate lines, which is fine in many cases. But when I wanted to display progress updates, format tabular data, or show a stream of results in real-time, I needed a way to keep everything on one line.

In this tutorial, I will show you step-by-step how to print in the same line in Python. I will cover multiple methods, explain when to use each one, and share complete code examples so you can try them out yourself.

Method 1 – Use the end Parameter in the print() Function

The simplest way to print in the same line is by using the end parameter in the print() function. By default, print() adds a newline character (\n) at the end of the output.

This is why every call to print() starts on a new line. If we change the end parameter, we can control what gets printed at the end.

Example:

# Printing numbers in the same line using end parameter
for i in range(1, 6):
    print(i, end=" ")

You can see the output in the screenshot below.

python print on same line

Here, instead of moving to a new line, Python prints all the numbers on the same line separated by spaces. This method is great when working with loops and when you want compact output.

Method 2 – Print Multiple Variables in the Same Line

Sometimes, I just want to print multiple variables without breaking the line. Python makes this easy because print() can take multiple arguments.

Example:

city = "New York"
state = "NY"
population = 8419600

print("City:", city, "| State:", state, "| Population:", population)

You can see the output in the screenshot below.

python print same line

This will print everything in a single line, separated by spaces by default.

If you want more control, you can use the sep parameter.

print("City:", city, "State:", state, "Population:", population, sep=" | ")

Output:

City: New York | State: NY | Population: 8419600

This is especially useful when formatting structured information like addresses, employee records, or sales reports.

Method 3 – Use sys.stdout.write()

In some cases, I prefer using sys.stdout.write() because it gives me more control over the output stream. Unlike print(), it does not automatically add a newline.

Example:

import sys

for i in range(1, 6):
    sys.stdout.write(str(i) + " ")
    sys.stdout.flush()

You can see the output in the screenshot below.

python print in same line

Here, sys.stdout.write() writes directly to the output buffer, and flush() ensures that the text appears immediately. This method is very useful when printing progress bars, live updates, or logs in real-time applications.

Method 4 – Use String Concatenation

Another way I often use is string concatenation. Sometimes, instead of printing values one by one, I build a single string and print it once.

Example:

numbers = ""
for i in range(1, 6):
    numbers += str(i) + " "

print(numbers.strip())

Output:

1 2 3 4 5

This method is efficient when you want to prepare the entire output first and then display it.

Method 5 – Use join() for Lists

If you are working with lists, the join() method is a clean and Pythonic way to print everything in the same line.

Example:

cities = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"]

print(" | ".join(cities))

Output:

New York | Los Angeles | Chicago | Houston | Phoenix

This is one of my favorite methods when working with datasets because it makes the code shorter and easier to read.

Method 6 – Print in the Same Line with Carriage Return

Sometimes, I want to update the same line instead of printing new lines. For example, when showing a progress bar or download status.

Example:

import time

for i in range(1, 11):
    print(f"Processing {i*10}%", end="\r")
    time.sleep(0.5)

This will update the same line repeatedly, giving the effect of a live progress bar.

This technique is widely used in command-line tools and data processing scripts.

Method 7 – Use print() with flush=True

In Python 3.3 and above, the print() function has a flush parameter. If you set flush=True, the output is written immediately without waiting for the buffer.

Example:

import time

for i in range(5):
    print("Task running...", end="\r", flush=True)
    time.sleep(1)

This is very handy when building real-time applications or when you want immediate feedback in the console.

Real-Life Example – Print Sales Data in One Line

Let me show you a more practical example. Suppose I am working with sales data for different states in the USA. I want to print the results in one line so that it looks neat.

Example:

sales_data = {
    "California": 120000,
    "Texas": 95000,
    "Florida": 87000,
    "New York": 110000
}

for state, sales in sales_data.items():
    print(f"{state}: ${sales}", end=" | ")

# Output: California: $120000 | Texas: $95000 | Florida: $87000 | New York: $110000 |

This format is compact and easy to read, especially when printing reports to the console.

Which Method Should You Use?

  • Use end parameter when printing inside loops.
  • Use multiple arguments in print() for structured output.
  • Use sys.stdout.write() for real-time logs or progress updates.
  • Use string concatenation or join() when working with large datasets.
  • Use carriage return \r or flush=True when you need live updates on the same line.

Most of the time, I use the parameter ‘end’ because it’s simple and works in almost every case. But when I need more control, I switch to sys.stdout.write() or carriage returns.

Printing in the same line may look like a small thing, but it makes a big difference in how clean and professional your scripts look. Over the years, I have found that choosing the right method saves me time and makes my code easier to understand.

You may 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.