Your decision is perfect. You do not need three branches, because str.upper() will return str if the top is not applicable.
Using generator expressions, this can be reduced to:
>>> name = 'Mr.Ed' >>> ''.join(c.lower() if c.isupper() else c.upper() for c in name) 'mR.eD'
ch3ka
source share