已知当前文件夹中文件example.txt中有一段文本,其中包含英文字母、数字、汉字和标点符号。编写程序,读取该文件中的全部内容,把大写字母变为小写字母,小写字母变为大写字母,其他符号不变,把处理后的文本写入新文件result.txt中。
请使用以下例子进行测试:
with open('result.txt','w',encoding='utf-8') as f1:
with open('example.txt',encoding='utf-8') as f :
f1.write(f.read().swapcase())