HackerRank sWAP cASE problem solution in python

In this Hackerrank sWAP cASE problem solution in python, we need to develop a program that can take a string as input, and then we need to convert all the lowercase letters of that string into uppercase and uppercase to lowercase.

HackerRank sWAP cASE solution in python

Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
name = raw_input()
print ''.join(c.lower() if c.isupper() else c.upper() for c in name)


Problem solution in Python 3 programming.

def swap_case(s):
    return s.swapcase()

Problem solution in pypy programming.

def swap_case(s):
    res = ''
    for ch in s:
        if ch.isupper():
            res += ch.lower()
        else:
            res += ch.upper()
    return res

Problem solution in pypy3 programming.

def swap_case(s):
    result = []
    for letter in s:
        if letter == letter.lower():
            result.append(letter.upper())
        elif letter == letter.upper():
            result.append(letter.lower())
        else:
            result.append(letter)
    return ''.join(result)