user3832061
user3832061

Reputation: 527

append a new line to a file python

I have a file that contains one line

car 

I want to append a new line to the file

when I used this code:

f = open("motors.txt","a")
f.write("Bicycle")

I got the following:

carBicycle

how could I append the new word to a new line

Upvotes: 1

Views: 11335

Answers (1)

user2555451
user2555451

Reputation:

Prefix Bicycle with a newline character (\n) to have it write on a new line:

f.write("\nBicycle")

Upvotes: 3

Related Questions