The sep Parameter in the Print Function in Python
This tutorial will explain the sep
parameter in the print()
function.
The print(objects, sep, end, file, flush)
function converts the objects
into strings and prints them to the provided file
text stream; the end
is the value that is appended at the end of the last input object
. The flush
is set True
if the user wants to flush the stream forcibly. The sep
argument is used as the separator that separates the objects
being printed by the print()
function.
the sep
Argument of the print()
Function in Python
The default value of the sep
argument is ' '
, which is why the multiple strings are printed by the print()
function and separated by the ' '
. The below example code demonstrates the output of the default value of the sep
argument when the print()
function is used:
print("hey", "hi", "hello")
Output:
hey hi hello
We can set the value of the sep
argument by ourselves and separate the input objects
(that we want to print) using the chosen sep
value. The below example code demonstrates how to use different values as the sep
argument of the print()
function in Python.
print("hey", "hi", "hello", sep="_")
print("hey", "hi", "hello", sep="\t")
print("hey", "hi", "hello", sep="\n")
Output:
hey_hi_hello
hey hi hello
hey
hi
hello