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:
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)
\nis escape sequence and represents a newline character, used to insert a line break or can say start a new line.- When
\nescape sequence is encountered within a string, it tells Python to move the cursor to the beginning of the next line.