Swap cases in a string

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

    def swap_case(s):
        a=" "
        for i in s:
            if i==i.lower():
                a=a+(i.upper())
            else:
                a=a+(i.lower())
        return (a)
    

提交回复
热议问题