Ram*_*rge -2 python string python-2.7
主题7:问题4编写改变单词中所有字母大小写的函数changeCase(word)并返回新单词.
例子
>>> changeCase('aPPle')
"AppLE"
>>> changeCase('BaNaNa')
'bAnAnA'
Run Code Online (Sandbox Code Playgroud)
我是python的初学者,我的错误在哪里?
def changeCase(word):
return ''.join(c.upper() if c in 'aeiou' else c.lower() for c in word)
Run Code Online (Sandbox Code Playgroud)
fal*_*tru 14
用途str.swapcase:
>>> 'aPPle'.swapcase()
'AppLE'
>>> 'BaNaNa'.swapcase()
'bAnAnA'
Run Code Online (Sandbox Code Playgroud)