sWAP cASE

Sort by

recency

|

1992 Discussions

|

  • + 0 comments

    we can use the simple swapcase function to do it

    def swap_case(s):

    return s.swapcase()
    

    if name == 'main': s = input() result = swap_case(s) print(result)

  • + 0 comments
    swap_case = str.swap_case
    
    if __name__ == '__main__':
        s = input()
    		result = swap_case(s)
    		print(result)
    
  • + 0 comments

    def swap_case(s): result = "" for i in s: if i.islower(): result += i.upper() elif i.isupper(): result += i.lower() else: result += i return result

  • [deleted]Challenge Author
    + 0 comments

    For Python3

    def swap_case(s):
        return s.swapcase()
     
    if __name__ == '__main__':
        s = input()
        result = swap_case(s)
        print(result)
    
  • + 0 comments

    new_str = "" for char in s: if not char.isalpha(): new_str += char elif char.isupper(): new_str += char.lower() elif char.islower(): new_str += char.upper() return new_str