Data house
[어이털리는 알고리즘] python 대소문자 변경 본문
728x90
문제
대소문자 변경해서 출력하는 간단한 문제
https://school.programmers.co.kr/learn/courses/30/lessons/181949
풀이
흔히 python에서 대소문자 문제 나오면,
1. 대소문자 확인 작업 : .isupper() .islower() 함수
2. 대/소문자 변경 작업: .upper() .lower() 함수
위의 과정 거치면 끝나는데 ㅋㅋㅋㅋ..
str = input()
for i in str:
if i.isupper():
print(i.lower(),end="")
else:
print(i.upper(),end="")
나는 이렇게 간단하게 풀었지만
더더 어이털리게 단 한 줄로 해결할 수 있다더라..
ㅋㅋㅋㅋㅋㅋㅋㅋ.... python은 진심 대단해
가장 인상깊었던 풀이
str = input()
print(str.swapcase())
썅
'Computer Knowledge > 코테 대비 오답노트' 카테고리의 다른 글
[python] str.replace() (0) | 2023.05.08 |
---|---|
python 부분 문자열 (0) | 2023.05.08 |
[어이털리는 알고리즘] python/string - raw string, join (1) | 2023.05.06 |
알고리즘과 시간복잡도 (0) | 2023.04.26 |
자료구조 (2) | 2023.04.26 |