大小写转换

时间:2020-04-03 20:14:20   收藏:0   阅读:79

编写程序,用户输入一个字符串,将其中小写字母全部转换成大写字母,把大写字母全部转换成小写字母,其他字符不变输出。????????????????????????????????????????????????????????????????????????????????????????????????

注:string.ascii_lowercase 可用于返回所有小写字母,string.ascii_uppercase 可用于返回所有大写字母

import string
str1 = input()
for i in str1:
    if i in string.ascii_lowercase:
        print(i.upper(),end="")
    elif i in string.ascii_uppercase:
        print(i.lower(),end="")
    else:
        print(i,end="")

 

原文:https://www.cnblogs.com/L-1008/p/12628498.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!