Search code examples
pythonstringtextkeyboardenter

How do I make text go on to the next line (enter/return effect)? Python


I have numerous strings which I am writing into a notepad txt.file via python using

x = open("File", "w")

However i want the strings to be written in the text file in the format:

('Hello')
('Hey')
('Whatever')

Instead of this:

('Hello')('Hey')('Whatever')

I'm missing specific code to achieve the 'keyboard enter/return' affect, so if anyone knows please drop me an answer. Also, I don't want to manually press enter in the actual text file, I want to do it via python. Thanks!


Solution

  • I thought I'd put my comment as an answer.

    Here is a related question: stackoverflow.com/questions/11497376/new-line-python.

    Essentially you should use a new line character which is \n. "\" is an escape character.