Coding test/알고리즘

[python] 대문자는 소문자로 소문자는 대문자로

코코맹 2024. 11. 8. 03:37

python에서 나이스한 함수

swapcase()를 쓰면

대문자는 소문자로 소문자는 대문자로 바꿀 수 있다.

 

다만 파이썬이 아니라면 어떤 알고리즘?

str = input()

for i in str:    
     if i.isupper() == True:
        print(i.lower(), end="")
    else:
        print(i.upper(), end="")