sep parameter in print() - Python

Last Updated : 17 Sep, 2025

In Python, the print() function is one of the most commonly used functions. By default, when you print multiple values, Python automatically separates them with a space. The sep parameter allows us to customize this separator. Instead of always using a space, one can define your own character (like -, @, |, etc.). This makes it very useful for formatting outputs in a clean and readable way.

By default, Python separates values with a space. Using sep, we can change this behavior.

Example: Default behavior

Python
print("A", "B", "C")

Output
A B C

Here, Python automatically inserts a space between values.

Note: sep is available only in Python 3.x and later.

Examples of sep parameter

Let’s look at some examples to better understand how the sep parameter works in different scenarios.

Example 2: Disabling spaces completely

Python
print("G", "F", "G", sep="")

Output
GFG

Explanation: Using sep="" removes all spaces between values.

Example 3: Using pipe | as separator

Python
print("Python", "Java", "C++", sep=" | ")

Output
Python | Java | C++

Explanation: This is useful for printing structured data like tables or logs.

Example 4: Adding custom separator @

Python
print("Oliver", "gmail.com", sep="@")

Output
Oliver@gmail.com

Explanation: This can be used to build email-like strings.

2. Combining sep with end

The end parameter controls what happens after print finishes (default is a newline \n). When used together with sep, you can format your output in creative ways.

Example 1: Printing values without newline

Python
print("G", "F", sep="", end="")
print("G")

Output
GFG

Explanation: Here, sep="" removes spaces, and end="" prevents a newline, so "GFG" appears in one line.

Example 2: Creating email-like output

Python
print("Oliver", "Jane", sep="", end="@")
print("gmail.com")

Output
OliverJane@gmail.com

Explanation: end="@" attaches an @ at the end of first print and second print continues from there, producing an email-like format.

3. Real-World Uses of sep

The sep parameter is not just for practice it is often used in real applications for formatting output.

Example 1: Formatting Dates

Python
print("2025", "09", "15", sep="-")  

Output
2025-09-15

Explanation: Useful for printing dates in a standard format.

Example 2: CSV-style output

Python
print("Name", "Age", "City", sep=", ")  

Output
Name, Age, City

Explanation: This mimics how data appears in CSV files.

Example 3: Building usernames

Python
print("Sarah", "Jane", sep=".") 

Output
Sarah.Jane

Explanation: Often used to generate usernames or IDs.

Example 4: Logging and debugging style

Python
print("ERROR", "File not found", sep=": ")

Output
ERROR: File not found

Explanation: A neat way to format log or error messages.

Comment
Article Tags:

Explore