반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Tkinter
- Google Spreadsheet
- Python
- array
- string
- PANDAS
- Github
- google apps script
- Excel
- Kotlin
- PostgreSQL
- django
- Presto
- hive
- PySpark
- GIT
- list
- math
- numpy
- Google Excel
- Redshift
- c#
- 파이썬
- Apache
- matplotlib
- SQL
- gas
- dataframe
- Java
Archives
- Today
- Total
달나라 노트
Python Basic : isnumeric (숫자로 변환될 수 있는 data인지 체크하기) 본문
Python/Python Basic
Python Basic : isnumeric (숫자로 변환될 수 있는 data인지 체크하기)
CosmosProject 2021. 3. 18. 20:00728x90
반응형
Python에 있는 isnumeric() method는 String type의 데이터에 적용할 수 있으며,
해당 String data가 숫자로 전환될 수 있는 data라면 True,
숫자로 전환될 수 없는 data라면 False를 반환합니다.
text1 = '1'
print(text1.isnumeric())
text2 = '1a'
print(text2.isnumeric())
text2 = 'Text Text'
print(text2.isnumeric())
-- Result
True
False
False
위 예시를 봅시다.
text1 -> 비록 따옴표로 1이라는 문자가 String으로서 되어있지만, 1은 숫자로 전환될 수 있겠죠? 따라서 isnumeric은 True를 반환합니다.
text2 -> 1a는 String이며 a라는 문자 때문에 당연히 숫자로 변환될 수 없습니다. 따라서 isnumeric은 False를 반환합니다.
text3 -> Text Text라는 문자도 당연히 숫자로 변환될 수 없으니 isnumeric은 False를 반환합니다.
728x90
반응형
'Python > Python Basic' 카테고리의 다른 글
| Python Basic : sorted, sort (list의 요소 정렬하기) (0) | 2021.03.29 |
|---|---|
| Python Basic : lower, upper (소문자로 변경하기, 대문자로 변경하기) (0) | 2021.03.27 |
| Python Basic : open (file 읽기) (0) | 2021.02.08 |
| Python Basic : map & filter 함수 (0) | 2021.01.24 |
| Python Basic : strip, lstrip, rstrip (문자열 가장 양쪽의 공백 제거하기. 문자열 가장 양쪽에 있는 특정 문자 제거하기) (0) | 2021.01.20 |
Comments