sep in python
In this post, you will learn about the sep argument of Python print() function.
The Python print() function prints the specified message to the screen. As we all know, the print function is the most basic while learning any programming language. By default, print() displays multiple objects separated by spaces. This method accepts 'sep' as an optional parameter. It specifies how to separate the objects in the event that we have more than one element. The default value is space ' '. The sep parameter specifies what to replace these spaces with. This attribute is available in Python 3.x or later versions.
Syntax of Python print()
print(object(s), sep=separator)
Here, 'sep' specifies the separator between the arguments. We can use any character, an integer or a string value in sep. The default value for sep is whitespace.
Example of Python sep
Here is the basic example of 'sep' attribute in Python.
# printing with using sep attribute
print('P','R','I','S','K','A', sep='')
# printing numbers with using sep attribute
print(11, 34, 50, sep=':')
# formatting a date using sep
print('18','09','2020', sep='-')
# formatting email using sep
print('priska','etutorialspoint.com', sep='@')
Output of the above code-
PRISKA
11:34:50
18-09-2020
This email address is being protected from spambots. You need JavaScript enabled to view it.
sep with end parameter
The sep parameter when utilized with the end parameter it produces great outcomes. These are the some examples by combining the sep and end parameter.
print('A','B', sep='', end='')
print('C')
print('31','7', sep='-', end='-2021\n')
print('demo','etp', sep='', end='@')
print('etutorialspoint')
Output of the above code -
ABC
31-7-2021
demoetp@etutorialspoint
Related Articles
Count consonants in a string Python
Remove character from string Python
Python multiline string
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple separators
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python compare two lists
Insert data in MySQL database from an HTML form using Django
Alphabet pattern programs in Python