Course contentsShow
← Python
Lesson 52 of 1,0601. Foundations and EnvironmentFree lesson

Controlling Output Streams with Print Parameters

Learners will be able to modify the appearance of console output by customizing separator characters and line-ending behaviors.

Controlling Output Streams with Print Parameters

In this lesson, you will learn how to customize the appearance of your console output by modifying the default behavior of the print() function.

When you use print(), Python adds invisible characters to your output automatically. By default, it places a space between multiple items you pass to it, and it moves to a new line after every function call. You can take control of this using the sep and end parameters.

The Separator Parameter (sep)

If you provide multiple arguments to print(), they are separated by a space by default. You can change this using the sep (separator) parameter.

print("Python", "is", "fun", sep="-")
# Output: Python-is-fun

By setting sep="-", you tell Python to insert a hyphen between each item instead of the usual space. You can use any string, including empty ones or complex symbols.

The End Parameter (end)

By default, every print() call finishes by printing a newline character (\n), which moves the cursor to the next line. You can change this behavior using the end parameter.

print("Hello", end=" ")
print("World")
# Output: Hello World

In this example, the first print() call replaces the default newline with a single space. This causes the second print() call to continue on the same line rather than starting a new one. This is incredibly useful when you want to build a line of text dynamically or create custom formatting for your console output.

You can even combine them to gain total control:

print("Loading", "Data", sep="...", end="!")
# Output: Loading...Data!

These parameters allow you to format your output precisely without needing to perform complex string concatenation or manual newline management.

Key Takeaway: Use the sep parameter to define how multiple items are joined, and use the end parameter to dictate what follows your output instead of the default newline.