반응형 str1 [Python] str find 사용하기 Python find 찾은 문자열의 index 를 리턴합니다. 못찾으면 -1 index 시작은 0 부터. 예제 #1 6 #2 14 #3 28 모두 찾기 string = 'hello ~ bryan ~ how are you ~' print('#1 ', string.find('~')) print('#2 ', string.find('~', 8)) print('#3 ', string.find('~', 15)) i = string.find('~') while i > -1: print(f'~ position = {i}') i = string.find('~', i+1) 출력 #1 6 #2 14 #3 28 ~ position = 6 ~ position = 14 ~ position = 28 2021. 6. 9. 이전 1 다음 728x90 반응형