1. isdigit()
문자열이 모두 숫자로 구성 : True
그 외 : False
str1 = '12345'
str2 = '12 34 5'
str3 = '12 34 5 ab'
print(str1.isdigit()) # True
print(str2.isdigit()) # False
print(str3.isdigit()) # False
2. isalpha()
문자열이 모두 문자로 구성 : True
그 외 : False
str1 = 'hello'
str2 = 'hello12'
str3 = 'hello hello'
print(str1.isalpha()) # True
print(str2.isalpha()) # False
print(str3.isalpha()) # False
3. isalnum()
문자열이 문자 또는 숫자로 구성 : True
그 외 : False
str1 = 'hello'
str2 = 'hello12'
str3 = 'hello hello'
print(str1.isalnum()) # True
print(str2.isalnum()) # True
print(str3.isalnum()) # False
'Developer > Python' 카테고리의 다른 글
[Python] Stack 구현하기 (0) | 2021.04.19 |
---|---|
[python] 큐(Queue) 라이브러리 사용하기 - Queue, LifoQueue, PriorityQueue (0) | 2021.04.10 |
[Python] collections 모듈 Counter 클래스 사용하기 (0) | 2021.01.31 |
[Python] 이벤트 루프 (0) | 2021.01.17 |
[Python] Python에서 fpdf 사용하기 (0) | 2021.01.05 |