可以用string的方法
string.ascii_lowercase 可用于返回所有小写字母
string.ascii_uppercase 可用于返回所有大写字母
import string
sentence = input('请输入一串字符:')
for i in sentence:
if i in string.ascii_lowercase: #字符是小写
print(i.upper(),end='')
elif i in string.ascii_uppercase: #字符是大写
print(i.lower(),end='')
else: #其他字符
print(i,end='')