Coding/Python
[python]isdigit()
후__아
2024. 6. 13. 14:06
※ 문자열.isdigit()
문자열이 '숫자'로만 구성돼있는지 확인하는 함수
따로 chr, ord 함수를 활용하지 않아도 간단하게 풀 수 있음!!
# 프로그래머스 lv1 문자열 다루기 기본
def solution(s):
a = [i for i in s if ord(i)>=48 and ord(i)<=57]
return (len(s) == 4 or len(s) == 6) and len(s) == len(a)
# 다른 사람 풀이
return s.isdigit() and len(s) in [4,6]