programmers- lv.1 (문자열 다루기 기본)

이예송·2023년 7월 11일

PS

목록 보기
23/97

문제링크: 문자열 다루기 기본

✍🏻 Information

content
언어python
난이도⭐️+0.5
풀이시간5분
제출횟수3
인터넷검색유무yes




🍒 My Code

def solution(s):
    answer = True
    if len(s)!=4 and len(s)!=6:
        answer = False
    else:
        answer = s.isdigit()
    return answer




💡 What I learned

  • 처음에 else문 안달아주고 그냥 answer=s.isdigit()해줘서 앞에 if문이 의미없고 isdigit 결과에 따라서만 answer이 좌우됐었다.
  • str.isdigit(): 문자열이 숫자로만 이루어져있는 경우 True 반환. 음수기호 -나 소수 .은 문자로 취급.
  • str.isdecimal(): 데이터가 int 타입으로 변환이 가능한 숫자인 경우 True 반환
  • str.isalpha(): 문자열이 문자로만 이루어져있는 경우 True 반환

0개의 댓글