-1

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!

user6842389
  • 49
  • 1
  • 4
  • 8

2 Answers2

0

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.

Community
  • 1
  • 1
USER_1
  • 2,409
  • 1
  • 28
  • 28
0

You can use triple quotes to include the returns without using \n.

Like this

"""Line1
Line2
Line3
"""
Quintus Chen
  • 53
  • 1
  • 5