The sep parameter in the print() function in Python is used to specify a string that separates multiple arguments when they are printed. By default, the print() function separates arguments with a space (' '), but you can change this behavior by providing a different string to the sep parameter.
Example of Using sep
Here’s a simple example:
print("Hello", "World", "from", "Labby", sep="-")
This will output:
Hello-World-from-Labby
In this case, the words are separated by a hyphen (-) instead of a space.
Using sep with Multiple Arguments
You can use sep with any number of arguments:
print(1, 2, 3, 4, sep=", ")
This will output:
1, 2, 3, 4
Summary
- Purpose: The
sepparameter defines the string that separates multiple arguments in the output. - Default Value: The default separator is a space (
' '). - Customization: You can customize the separator to any string you want, such as commas, hyphens, or even empty strings.
If you have more questions about the sep parameter or anything else, feel free to ask!
