문제
길이가 N인 영어로 이뤄진 문자열 S가 주어진다. 이 문자열 S가 철자가 대문자라면 소문자로, 소문자라면 대문자로 바꿔서 출력하시오.
입력
첫째 줄에 문자열의 길이 N이 주어진다.
둘째 줄에 길이가 N인 문자열 S가 주어진다. 모든 문자열은 알파벳으로 이루어져 있다.
- 1 ≤ N ≤ 10,000
n = int(input())
s = input()
alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in s:
if i in alpha:
print(i.upper(), end = "")
else:
print(i.lower(), end = "")
lower()와 upper() 함수 사용
import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
result = ''
for i in S:
if i.islower():
result += i.upper()
elif i.isupper():
result += i.lower()
print(result)
swapcase() 사용
import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
print(S.swapcase())
※출처
https://multicampus-kdt.goorm.io/lecture/38996/멀티잇-코딩테스트-러닝클래스-python-6월반