
Skip Line \n
Summary:
- Python’s newline character
\n
indicates the end of a line of text. - The built-in
print()
function automatically adds a newline character\n
at the end. - You can customize this behavior of separating two lines using a single newline character
'\n'
by changing the defaultend='\n'
argument of theprint()
function to your desired string. - Another way to skip a line in the Python output is to add an empty
print()
statement that will just print an empty line and do nothing else.
Python’s newline character to indicate the end of a line of text is \n
.
If you print a string to the shell using the built-in print()
function, Python automatically adds a newline character \n
at the end.
PYTHON CODE:print('hello\nworld\n\nPython is great!')
OUTPUT:hello world Python is great!
For example, if you iterate over the text in a file using a for
loop and print each line in the loop body, the lines are separated with single new lines.
################################# # File: my_filename.txt # ################################# # My # # File # # Content # ################################# with open('my_filename.txt', 'r') as my_file: for line in my_file.readlines(): print(line) # Output: My File Content
You can customize this behavior of separating two lines using a single newline character '\n'
by changing the default end='\n'
argument of the print()
function to your desired string.
For example, you can skip two lines in Python using print(my_string, end='\n\n')
by chaining two newline characters '\n\n'
.
with open('my_filename.txt', 'r') as my_file: for line in my_file.readlines(): print(line, end='\n\n') # Output: My File Content # End Output
Another way to skip a line in the Python output is to add an empty print()
statement that will just print an empty line and do nothing else.
with open('my_filename.txt', 'r') as my_file: for line in my_file.readlines(): print(line) print() # Output: My File Content # End Output

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.