文件src.txt存储的是一篇英文文章, 将其中所有大写字母转换成小写字母存入文件dest.txt。
2条回答 默认 最新
- benbenli 2021-05-07 02:27关注
f = open('src.txt', 'r') text = f.read() lines = [line.lower() for line in text] with open('dest.txt', 'w') as out: out.writelines(lines)
运行结果:
$ cat src.txt f = OPEN('src.txt', 'r') text = f.READ() lines = [line.LOWER() FOR line IN text] WITH OPEN('dest.txt', 'w') AS OUT: OUT.WRITELINES(lines) $ python3 lower.py $ cat dest.txt f = open('src.txt', 'r') text = f.read() lines = [line.lower() for line in text] with open('dest.txt', 'w') as out: out.writelines(lines) $
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用