When working with Python, it’s important to be familiar with the language’s built-in functions. One of these functions is print()
, which is used to output text to the console. While print()
is a relatively simple function, it has many parameters that can be used to customize its behaviour. One of the most important of these parameters is sep. So Let’s see Sep Parameter in Python
The sep
parameter is used to specify the separator between the different items that are being printed. By default, the separator is a single space character. However, this can be changed by passing a different value to the sep
parameter.
For example, consider the following code:
print("apple", "banana", "orange")
This code will output the following text:
apple banana orange
If we wanted to separate each item with a comma instead of a space, we could use the sep parameter like this:
print("apple", "banana", "orange", sep=", ")
This code will output the following text:
apple, banana, orange
As you can see, the sep
parameter can be used to change the separator between the different items that are being printed. This can be useful in a variety of situations, such as when printing out lists or tuples.
Another way to use the sep
parameter is to pass an empty string as its value. This will effectively remove the separator between the different items, resulting in them being printed right next to each other. For example:
print("apple", "banana", "orange", sep="")
This code will output the following text:
applebananaorange
In conclusion, the sep parameter is a powerful tool that can be used to customize the behaviour of the print()
function. By changing the separator between the different items being printed, you can create output that is more readable and easier to understand. Whether you’re working with lists, tuples, or just plain text, the sep parameter is a valuable tool to have in your Python arsenal.
If you want to learn more about the python, here is the tag list of the python.