Sep parameter

Code Examples

Example 1

Comma and space as separator. A comma and space are inserted between the values.

print("apple", "banana", "cherry", sep=", ")  
# Output: apple, banana, cherry

Example 2

Custom separator (hyphen). A hyphen is inserted between the values instead of a space. Useful for formatting dates or ID numbers.

print("Hello", "World", sep="-") 
# Output: Hello-World

Example 3

An empty string as a separator glues the values together without any space or symbol between them.

first = "Code"
second = "123"
print(first, second, sep='')
# Output: Code123

Example 4

Using newline as separator.

print("Warning", "Error", "Critical", sep="\n") 
# Output:
# Warning
# Error
# Critical