The separator between the parameters of the print() function in Python defaults to a space (soft space function), which can be modified to any character, integer or string according to our choice. The ‘sep’ parameter is used to achieve the same function and can only be found in python 3.x or higher. It is also used to format the output string.
Examples:
In Python, the print()
function is used to display text or other objects on the console or in a file. It is a built-in function in Python and has various parameters that can be used to customize its behavior. One of these parameters is the sep
parameter.
The sep
parameter in the print()
function is used to specify the separator between the objects that are passed as arguments to the function. By default, the sep
parameter is set to a space character (' '), which means that the objects are separated by a space.
For example, consider the following code:
print('apple', 'banana', 'orange')
The output of this code would be:
apple banana orange
However, if we want to change the separator to a comma, we can do so by passing the sep
parameter to the print()
function as follows:
print('apple', 'banana', 'orange', sep=', ')
The output of this code would be:
apple, banana, orange
In this example, the separator between the objects is a comma followed by a space character, which was specified using the sep
parameter.
In summary, the sep
parameter in the print()
function is used to specify the separator between the objects that are passed as arguments to the function. It can be used to customize the output of the print()
function according to the specific requirements of the program.