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

Python print/write

Ok so, when I print text and text1 it displays something like this:

END OF TEXT HERE BEGINNING OF TEXT1 HERE

I want the output to be like this for both print and write:

END OF TEXT HERE
BEGINNING OF TEXT1 HERE

I want the output to be like this for both print and write:

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

END OF TEXT HERE
BEGINNING OF TEXT1 HERE

I tried split(), but I think I’m doing it in the wrong area..Thanks for the help.

My Code is below:

print(text, text1)

with open("text.txt", "w+", encoding="utf-8") as file:
    file.write(text + text1)

>Solution :

Assuming the values of text and text1

text="END OF TEXT HERE"
text1="BEGINNING OF TEXT1 HERE"
print(text + "\n" + text1)

with open("text.txt", "w+", encoding="utf-8") as file:
    file.write(text + "\n" + text1)
  • \n is escape sequence and represents a newline character, used to insert a line break or can say start a new line.
  • When \n escape sequence is encountered within a string, it tells Python to move the cursor to the beginning of the next line.
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