Swap cases in a string

后端 未结 10 624
天涯浪人
天涯浪人 2021-01-21 15:20

I\'m trying to solve this challenge in hackerrank, which asks to convert all lowercase letters to uppercase letters and vice versa.

I attempt it with the following code:

10条回答
  •  借酒劲吻你
    2021-01-21 15:30

    Python-3 in-built swapcase function.

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

    Input:

    "Pythonist 3"
    

    Output:

    "pYTHONIST 3"
    

提交回复
热议问题