728x90
def solution(my_string):
answer = []
for c in my_string:
if c.islower():
answer.append(c.upper())
else:
answer.append(c.lower())
return ''.join(answer)
def solution(my_string):
return my_string.swapcase()
swapcase()
- 대문자는 소문자로, 소문자는 대문자로 변환해주는 함수이다.
- 이 함수를 알았다면 훨씬 간단하게 문제를 해결할 수 있었을 듯!
728x90
'CodingTest > [프로그래머스 LV.0]' 카테고리의 다른 글
프로그래머스 LV.0 - 직각삼각형 출력하기[Python] (1) | 2023.01.22 |
---|---|
프로그래머스 LV.0 - 암호 해독[Python] (0) | 2023.01.22 |
프로그래머스 LV.0 - n의 배수 고르기[Python] (0) | 2023.01.22 |
프로그래머스 LV.0 - 세균 증식[Python] (0) | 2023.01.22 |
프로그래머스 LV.0 - 개미 군단[Python] (0) | 2023.01.22 |