我试图在.txt文件中添加换行符,但是当我使用“\ n”时,没有任何内容发生。如何在.txt文件中添加换行符?这是我的代码:

时间:2021-08-05 19:36:32
f = open("Words.txt", "w")

for i in range(5):

    f.write("s"* i)
    f.write("\n")
f.close()


elice_utils.send_file('words.csv') 

1 个解决方案

#1


0  

Code:

f = open("Words.txt", "w")

for i in range(5):

    f.write("s" * i)
    f.write("\n")
f.close()

output:

s
ss
sss
ssss

Tell me if this is not your expected output. I will update it

告诉我这是不是你预期的输出。我会更新它

#1


0  

Code:

f = open("Words.txt", "w")

for i in range(5):

    f.write("s" * i)
    f.write("\n")
f.close()

output:

s
ss
sss
ssss

Tell me if this is not your expected output. I will update it

告诉我这是不是你预期的输出。我会更新它