The Separator and End Arguments of the Python Print Function

Everybody knows the print function in Python. It prints a string to the shell–and makes the computation of a Python program explicit to the programmer. But what other arguments can be used to format the output?

There are two other arguments: sep and end. Consider the following example:

a = 'hello'
b = 'world'

print(a, b, sep=' Python ', end='!')

The print function has several parameters which you can use to format the output.

The parameter sep indicates the separator which is printed between the objects. By default sep is empty space. In the puzzle we set it to be ‘ Python ‘.

The parameter end defines what comes at the end of each line. By default end is a line break. In the puzzle we set it to '!'. This means that print would print everything in one single line because there is no line break.

When we call print() with the given parameters and objects a and b we get the output ‘hello Python world!’

Leave a Comment

Your email address will not be published. Required fields are marked *