Python 2.7 - 在新行上写入字符串

Python 2.7 - writing string on a new line

py 2.7 当我调用 a.write() 时,我想在我的字符串中添加一个新行 问题是内容是一个变量。 所以,当我写

a.write(x,"/n") 

它给我错误,因为我不能在 () 中放置超过 1 个参数。 有什么建议吗?

有很多方法可以实现

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

注意 - \n 是换行符而不是 /n