sep parameter in print()

Course Curriculum

sep parameter in print()

sep parameter in print()

The separator between the arguments to print() function in Python is space by default (softspace feature) , which can be modified and can be made to any character, integer or string as per our choice. The ‘sep’ parameter is used to achieve the same, it is found only in python 3.x or later. It is also used for formatting the output strings.

Examples:

#code for disabling the softspace feature
print('P','A','I', sep='')

#for formatting a date
print('09','12','2016', sep='-')

#another example
print('rishabh','prutor', sep='@')
Output:

PAI
09-12-2016
rishabh@prutor
The sep parameter when used with the end parameter it produces awesome results. Some examples by combining the sep and end parameters.

print('P','A', sep='', end='')
print('I')
#n provides new line after printing the year
print('09','12','2016', sep='-', end='n')

print('prutor','ai', sep='.'')

Output:

PAI
09-12-2016
prutor.ai

Python end parameter in print() (Prev Lesson)
(Next Lesson) Python | Output Formatting