假设有一个英文文本文件,编写程序读取其内容,并将其中的大写字母变为小写字母,小写字母变为大写字母。
def up22low(filepath):
res = ''
with open(filepath, 'r') as f:
contents = f.readlines()
for content in contents:
for i in content:
if i.islower():
res += i.upper()
elif i.isupper():
res += i.lower()
else:
res += i
return res
if __name__ == '__main__':
filepath = 'h.txt'
print(up22low(filepath))