Q.

문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요. 예를 들어 s가 "a234"이면 False를 리턴하고 "1234"라면 True를 리턴하면 됩니다.

 

 

def solution(s):
    answer = True
    if len(s) == 4 or len(s)==6:
        for i in s:
            if i not in '0123456789':
                answer = False
    else:
        answer = False
        
    return answer

 

def alpha_string46(s):
    return s.isdigit() and len(s) in (4, 6)

isdigit() 숫자인지 확인하기

isalpha() 알파벳인지 확인하기 

+ Recent posts