"""
Everyone has his own dream
which can be realized or not and which can be different from time to time
However,there must be a longtern one in one's mind
"""# 将文件内容全部读取出来,打印到控制台上withopen('user.txt',encoding='utf-8')as f:print(f.readlines())# 在文件末尾追击1行,内容为In other words,it is not easy to be realizedwithopen('user.txt','a',encoding='utf-8')as f:
f.write('\nIn other words,it is not easy to be realized')# 将文件内容读取出来,并在每1行的额前面加上English Content: ,最后再输出withopen('user.txt',encoding='utf-8')as f:for i in f.readlines():print(f'English Content:{i}')"""删除aa.txt中的内容,换成如下内容
It's a11 written by Hu. In fact, I don't know what these English mean"""withopen('user.txt','w',encoding='utf-8')as f:
f.write("It's a11 written by Hu. In fact, I don't know what these English mean")
有一个 bb.txt 文件,内容都是英文小写,将文件内容都改成英文大写
withopen('bb.txt',encoding='utf-8')as f:for i in f.readlines():print(i.upper()if i.islower()else i)