Swapping uppercase and lowercase in a string

If you want to invert the case of that string, try this:

>>> 'AltERNating'.swapcase()
'aLTernATING'

There are two answers to this: an easy one and a hard one.

The easy one

Python has a built in function to do that, i dont exactly remember what it is, but something along the lines of

string.swapcase()

The hard one

You define your own function. The way you made your function is wrong, because iterating over a string will return it letter by letter, and you just return the first letter instead of continuing the iteration.

def to_alternating_case(string):
    temp = ""
    for character in string:
        if character.isupper() == True:
            temp += character.lower()
        else:
            temp += word.upper()
    return temp