python核心编程第六章练习6-10

6-10.
字符串。写一个函数,返回一个跟输入字符串相似的字符串,要求字符串的大小写反转,比如,输入“Mr.Ed”,应该返回“mR.eD”作为输出。
【答案】
代码如下:

#!/usr/bin/env python
from lib2to3.fixer_util import String

#string lower into upper,upper into lower
input = raw_input('Please input a string: ')
output = ''
for i in input:
    if i == i.upper():
        output = output + i.lower()
    else:
        output = output + i.upper()
print output

  运行

Please input a string: aBCd.eFx
AbcD.EfX

  

原文地址:https://www.cnblogs.com/Kaivenblog/p/4635878.html