Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print newline in Python without an automatic indent in the next line?

I was incorporating the \n command into my code to print the next part onto the next time.
While the original goal was achieved, there was an unexpected indent only for the first line of the result that started on the newline.

print("Rank:\n", rank_desc)

That results in:

Rank:
 count   500.000000
mean   250.500000
std    144.4181833
min      1.000000
etc...

One way to solve the issue is to just have two print statements.
However, now matter how I sliced and mixed the \n in my code, I could not get the indent to go away.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use sep parameter of print for this:

# sep stands for separator
print("Rank:", rank_desc, sep='\n')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading