'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
- Might be less readable due to no mention of
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.
Solution 1:[1]
Neither. The usual way would be:
print()
Solution 2:[2]
Most simple and shorter method is :
print()
Solution 3:[3]
Note in Python 2.x printing a newline is a simple as:
print
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Md. Rezwanul Haque |
| Solution 3 | Ajax1234 |
