8-1 文件编程7-1 - python文件基础

记得更换文件地址

f=open("F:\\vsnode\\python\\example.txt","r+")
str=f.read()
f.close()
ans=[]
for i in str:
    if i.isupper():
      ans.append(i.lower())
    if i.islower():
       ans.append(i.upper())
print(str)
ans_str="".join(ans)
print(ans_str)
f=open("F:\\vsnode\\python\\result.txt","r+")
f.write(ans_str)
f.close()

posted @ 2022-06-02 15:44  kingwzun  阅读(84)  评论(0编辑  收藏  举报