【发布时间】:2020-08-25 01:39:06
【问题描述】:
我正在尝试将变量中的数据附加到 Python 文件的末尾 - 在新行上。我使用了这种方法:(variable+"/n"),但在文件中,它在一行中包含所有文件数据,包括/n 符号。
我的代码(这是一个例子!所以这正是我想要回答的内容):
list = ["apple","pear","strawberry"]
f = open("test.txt","a")
for x in list:
f.write(x+"/n")
print(x)
f.close()
test.txt 中的输出:
apple/npear/nstrawberry/n
我该怎么做才能使输出看起来像这样:
apple
pear
strawberry
提前感谢您的回答!
【问题讨论】:
-
"/n" != "\n"...