문제
![](https://velog.velcdn.com/images%2Fcosmos%2Fpost%2F446a017b-9d29-4fed-ad41-2049b73e07c4%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-08-11%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.17.16.png)
풀이
- You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
- Complete the swap_case function in the editor below.
- swap_case has the following parameters:
- string s: the string to modify
Returns -> string: the modified string
- Input Format : A single line containing a string s.
코드
def swap_case(s):
result = [x.lower() if x.isupper() else x.upper() for x in s]
return ''.join(result)
if __name__ == '__main__':
word = str(input())
print(swap_case(word))
결과
![](https://velog.velcdn.com/images%2Fcosmos%2Fpost%2Fda72498c-4ba0-4889-bc0f-30fd94154000%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-08-11%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.29.12.png)
출처 && 깃허브
HackerRank
github