728x90
문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
해결코드
def solution(my_string):
answer = ''
#my_string문자열에서 반복문을 실행
for i in my_string:
#만약 문자열의 i가 대문자라면
if i.isupper():
#소문자로 바꿈
answer += i.lower()
#그렇지 않다면 = i가 소문자라면
else:
#i를 대문자로 바꿈
answer += i.upper()
#각 i에 따라 바뀐 answer를 출력함
return answer
isupper()는 해당 문자열이 대문자인지 여부를 확인할 때 사용한다
# example string
string = "THIS IS GOOD!"
print(string.isupper());
-> output: True
# numbers in place of alphabets
string = "THIS IS ALSO G00D!"
print(string.isupper());
-> output: True
# lowercase string
string = "THIS IS not GOOD!"
print(string.isupper());
-> output: False
islower()는 해당 문자열이 소문자인지 여부를 확인할 때 사용한다
a = "Hello world!"
b = "hello 123"
c = "mynameisPeter"
print(a.islower())
-> output: False
print(b.islower())
-> output: True
print(c.islower())
-> output: False
'프로그래밍 > 알고리즘' 카테고리의 다른 글
프로그래머스 - 배열의 유사도 파이썬 (0) | 2022.11.17 |
---|---|
프로그래머스 - 약수 구하기 파이썬 (0) | 2022.11.16 |
프로그래머스 - 중복된 문자 제거 파이썬 (0) | 2022.11.14 |
프로그래머스 - 최댓값 만들기(1) 파이썬 (0) | 2022.11.11 |
프로그래머스 - 배열 회전시키기 (0) | 2022.11.10 |
댓글