HANZO
HANZO

Reputation: 55

Python 2.7 - writing string on a new line

py 2.7 I want to append a new line to my string when I call a.write() the problem is that the contenent is a variable. so, when i write

a.write(x,"/n") 

it gives me error cause i can't put more than 1 argument in (). any suggest?

Upvotes: 0

Views: 11918

Answers (1)

Bhargav Rao
Bhargav Rao

Reputation: 52071

There are many ways of doing it

  • a.write(x+"\n")
  • a.write('{}\n'.format(x)
  • a.write('%s\n'%(x))

Note - \n is newline and not /n

Upvotes: 3

Related Questions