Kalyan Kumar
Kalyan Kumar

Reputation: 407

Why the print('\n', 'abc') in Python 3 is giving new line and an empty space?

I was just expecting a new line character and written below code.

>>> print('\n', 'abc')

 abc
>>>

But it gave single space also in front of the string abc, may I know why it added that space?

I am using Python 3.9 in Windows 10

Upvotes: 0

Views: 63

Answers (2)

Learning is a mess
Learning is a mess

Reputation: 8277

The default separator (sep) argument to the print function is a whitespace. Change it for a empty string to remove that single space indentation:

print('\n', 'abc', sep='')

Upvotes: 0

LeopardShark
LeopardShark

Reputation: 4446

If given more than one argument, print joins them with spaces, so you are effectively doing print("\n abc").

Upvotes: 2

Related Questions