Python | 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:
Python3
Output:
The sep parameter when used with the end parameter it produces awesome results. Some examples by combining the sep and end parameters.
Python3
Output:
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 )
Python3
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@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.
using the sep parameter in the print() function:
By default, the sep parameter is set to a space character, so if you don’t specify it explicitly, the values will be separated by a space.
Approach:
The code is using the print() function to print out strings with different separators. The sep parameter of the print() function is used to specify the separator between the strings. In the first example, a comma is used as the separator, in the second example, a semicolon is used, and in the third example, an emoji is used.
Time Complexity:
The time complexity of the print() function is O(n), where n is the total number of characters to be printed. However, the time complexity of specifying a separator is O(1), as it is a constant time operation.
Space Complexity:
The space complexity of the code is also O(n), where n is the total number of characters to be printed. This is because the print() function needs to allocate memory to store the strings and separators before printing them out.
Overall, the code has a constant time complexity for specifying the separator, and a linear time and space complexity for printing out the strings and separators.
How do I add space between two variables after a print in Python
I’m fairly new to Python, so I’m trying my hand at some simple code. However, in one of the practices my code is supposed to display some numbers in inches on the left and the conversion of the numbers on the right;
I want the output to be printed with some space between them;
I can’t figure out how to do this. I’ve searched everywhere, but all I can find are people trying to get rid of space. If someone could just lead me in the right direction, I’d be thankful.
Oh, and I just realized that I’m using Python 2.7, not 3.x. Not sure if this is important.
11 Answers 11
A simple way would be:
If you need more spaces, simply add them to the string:
A fancier way, using the new syntax for string formatting:
Or using the old syntax, limiting the number of decimals to two:
![]()
You can do it this way in Python 3:
![]()
Alternatively you can use ljust/rjust to make the formatting nicer.
A quick warning, this a pretty wordy answer.
print is tricky sometimes, I had some problems with it when I first started. What you want is a few spaces in between two variables after you print them right? There’s many ways to do this, as shown in the above answers.
This is your code:
It’s output is this:
If you want spaces in between, you can do it the naive way by sticking a string of spaces in between them. The variables count and conv need to be converted to string types to concatenate(join) them together. This is done with str().
To do this is the newer, more pythonic way, we use the % sign in conjunction with a letter to denote the kind of value we’re using. Here I use underscores instead of spaces to show how many there are. The modulo before the last values just tells python to insert the following values in, in the order we provided.
I used %i for count because it is a whole number, and %s for conv, because using %i in that instance would provide us with «2» instead of «2.54» Technically, I could’ve used both %s, but it’s all good.
Sep in Python | Examples, and Explanation

Hello coders!! In this article, we will cover sep in python. It may happen at times that we want to print formatted multiple values in a Python program. The sep argument in Python comes to play in such scenarios. Without wasting any time, let’s dive straight into the topic.
The sep parameter in Python:
Sep is a parameter in python that primarily formats the printed statements in the output screen. Whitespace is the default value of this parameter. It adds a separator between strings to be printed. Let us see some examples to make our concept clear.
Syntax:
Example 1: Python sep =”
![]()
As we can see, when the value of sep is empty, there is no gap between the two statements.
Example 2: Python sep = ‘\n’

In this example, when we use the sep value ‘, ‘ the list’s values are printed in a comma-separated fashion. When the value of sep is ‘\n,’ i.e., newline, the list’s value is printed in a new line every time.
Example 3: Joining a list with a separator in Python
In this particular example, we first declared a list of colors containing four values: red, blue, orange, and pink. We then declared the sep value as ‘ _’. When we joined the list using that separator, we can see that in the output the value of the list is printed with the separator.
Example 4: Parsing a string in python with sep
As we can see here, the value of the separator is a comma. As a result, the string is split at the places where there is a presence of a comma in the sentence.
Difference between sep and end:
| end | sep |
| prints once all the values in the given print statement is printed | separates the print value by inserting the given value between them |
| Example: st1=’python’ st2=’pool’ print(st1,st2,end=’%’) |
Conclusion:
With this, we come to an end to this article. The concept of sep for print statement formatting is relatively easy and simple. It finds major use in coding all over.
However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.
Как сделать пробел в Python
В этой статье мы рассмотрим, как сделать пробел в Python. В Python пробелы играют важную роль для форматирования и читаемости кода.
Создание пробела с помощью строки
Простейший способ создать пробел в Python – использовать строку с пробелом. Пример:
В данном примере мы используем оператор конкатенации + для объединения двух строк и строки с пробелом.
Создание пробела с помощью f-строки
С использованием f-строки можно также создать пробел в коде. Пример:
Здесь мы используем f-строку, которая позволяет вставить значения переменных внутри строки сразу в фигурных скобках, разделяя их пробелом.
Создание пробела с помощью метода join()
Ещё один способ создать пробел в Python – использовать метод join() . Пример:
В данном примере мы используем метод join() , который объединяет элементы списка в одну строку, разделяя их пробелом.
Создание пробела с помощью функции print()
Можно также использовать функцию print() для автоматического добавления пробела между аргументами. Пример:
В этом случае функция print() автоматически добавляет пробел между аргументами.