문자열중에 숫자를 찾고 싶을때 주로 썼는데 문득 궁금한게 생겨서 알아봤습니다
s="1a2b3c4d"
for i in range(len(s)):
if s[i].isnumeric():
print("%d index is numeric"%(i))
위와 같은 코드를 실행시키면 아래와 같은 결과가 나오게 됩니다.
1,2,3,4 가 numeric 하다는 뜻인데..
s="1a2b3c4d"
answer=0
for i in range(len(s)):
if s[i].isnumeric():
print("%d index is numeric"%(i))
answer+=s[i]
그럼 숫자에 대해 연산을 해볼까요?
Type이 int형과 str형이라 다르다고 뜨네요
공식문서를 참고해봤습니다
신기한건 U+2155 ⅕ 도 numeric으로 쳐주네요
Vulgar fraction은 수학용어인데 분모가 10의 배수가 아닌 분수 라고보시면됩니다
참조:
https://docs.python.org/3/library/stdtypes.html#str.isnumeric
반응형
'python-기타' 카테고리의 다른 글
Google Analytics Data API과 Python을 활용한 데이터 수집(Data collection using Google Analytics Data API and Python) (0) | 2023.05.11 |
---|---|
split(), split(" ")의 차이점 (0) | 2022.10.26 |
print vs pprint (0) | 2021.12.30 |
reverse 와 reversed 차이 (0) | 2021.12.28 |
댓글