一、读取文件,打印第三行时后面加入“徐亚平”
程序如下:
count=0
with open("test",mode="r",encoding="utf8") as f:
for line in f:
if count==2:
line="".join([line.strip(),"徐亚平"])
print(line.strip())
count+=1
1 Somehow, it seems the love I knew was always the most destructive kind 2 不知为何,我经历的爱情总是最具毁灭性的的那种 3 Yesterday when I was young 4 昨日当我年少轻狂 5 The taste of life was sweet 6 生命的滋味是甜的 7 As rain upon my tongue 8 就如舌尖上的雨露 9 I teased at life as if it were a foolish game 10 我戏弄生命 视其为愚蠢的游戏