Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most Pythonic way to print a newline

If I need to print a single newline, what is the most Pythonic way to write the print() statement? I am teaching someone Python and I want to do it right.

The two ways that I found most likely were:

1) print("")

  • Pros: Shorter and more simple
  • Cons:
    • Might be less readable due to no mention of \n
    • Relies on end being a newline, which may not be inherently obvious

2) print("\n", end = "")

  • Pros: It is obvious what the statement is meant to do
  • Cons: Longer. Beginner might not know what the 'end' argument means.
like image 638
Alex Binnard Avatar asked Aug 08 '17 18:08

Alex Binnard


2 Answers

Neither. The usual way would be:

print()
like image 96
wim Avatar answered Sep 28 '22 06:09

wim


Most simple and shorter method is :

print()
like image 31
Md. Rezwanul Haque Avatar answered Sep 28 '22 06:09

Md. Rezwanul Haque