Swap cases in a string

后端 未结 10 629
天涯浪人
天涯浪人 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:33

    The built-in str.swapcase already does this.

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

提交回复
热议问题