+ 2

How the sep and end is used in python print function?

24th Feb 2019, 2:42 PM
Sandeep Mehta
Sandeep Mehta - avatar
2 Answers
+ 7
Let's say you want to print 1-2-3-4@. You can easily do this using sep and end: print(1, 2, 3, 4, sep="-", end="@")
24th Feb 2019, 3:04 PM
Diego
Diego - avatar
+ 3
The default for sep is ' ' and the default for end is '\n' (newline). That's why every print starts in a new line and when you print several variables or something, they are separated by a space. Now by changing sep and end, you can arbitrarily change that behaviour to something else as Diego demonstrated.
24th Feb 2019, 3:34 PM
HonFu
HonFu - avatar