문자열 다루기 기본_프로그래머스_파이썬
- 사전지식
- isdigit()
- isdigit은 입력된값에 문자가 있으면 Fasle를 반환합니다
"a234".isdigit()
False
"1234".isdigit()
True
- 나의 풀이
import re
def solution(s):
origin = len(s)
if len(s) == 4 or len(s) == 6:
s_new = re.sub('[^0-9]', "",s)
if len(s_new) < origin:
return False
else :
return True
else :
return False
print(solution("1235"))
True
- 다른 사람 풀이
def alpha_string46(s):
return s.isdigit() and len(s) in (4, 6)
# 아래는 테스트로 출력해 보기 위한 코드입니다.
print( alpha_string46("a234") )
print( alpha_string46("1234") )
False
True
Comments