码迷,mamicode.com
首页 > 其他好文 > 详细

大小写转换

时间:2020-04-03 20:02:26      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:case   import   asc   span   ase   用户输入   print   upper   用户   

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

注: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="")

 

大小写转换

标签:case   import   asc   span   ase   用户输入   print   upper   用户   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!