-1

In python3 print('\n') will generate an extra blank line. Could someone make a brief explanation about this?

Thanks in advance.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253

1 Answers1

2

In the documentation for print it is stated that:

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end.

The default value for end is '\n', so Python first prints the supplied '\n' and then end which equals '\n' too; that's why you see two blank lines.

Change the default value if you don't want that:

print('\n', end='')

Note that this also applies to Python 2.x's print statement, it also writes '\n' at the end. You can change the behavior there by appending a comma character.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253