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('G','F','G', sep='') #for formatting a date print('09','12','2016', sep='-') #another example print('pratik','geeksforgeeks', sep='@') |
Output:
GFG 09-12-2016 pratik@geeksforgeeks
The sep parameter when used with end parameter it produces awesome results. Some examples by combining the sep and end parameter.
print('G','F', sep='', end='') print('G') #\n provides new line after printing the year print('09','12', sep='-', end='\n') print('prtk','agarwal', sep='', end='@') print('geeksforgeeks') |
Output:
GFG 09-12-2016 prtkagarwal@geeksforgeeks
Note: Please change the language from Python to Python 3 in the online ide.
Go to your interactive python ide by typing python in your cmd ( windows ) or terminal ( linux )
#import the below module and see what happens import antigravity #NOTE - it wont work on online ide |
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python end parameter in print()
- file parameter of Python's print() Function
- Python | Key-Value to URL Parameter Conversion
- Python | Split and Pass list as separate parameter
- Use of na_values parameter in read_csv() function of Pandas in Python
- Positional-only Parameter in Python3.8
- Mahotas - Parameter-Free Threshold Adjacency Statistics
- Python Program to print digit pattern
- itertools.combinations() module in Python to print all possible combinations
- Print number with commas as 1000 separators in Python
- heapq in Python to print all elements in sorted order from row and column wise sorted matrix
- Print anagrams together in Python using List and Dictionary
- Ways to print escape characters in Python
- Python code to print common characters of two Strings in alphabetical order
- Print powers using Anonymous Function in Python
- Print lists in Python (4 Different Ways)
- Python | Print the initials of a name with last name in full
- Print first m multiples of n without using any loop in Python
- Program to print all distinct elements of a given integer array in Python | Ordered Dictionary
- Python program to print checkerboard pattern of nxn using numpy

