Skip to content

Instantly share code, notes, and snippets.

@Gomi-coder
Created February 15, 2023 01:12
Show Gist options
  • Save Gomi-coder/6c69733c623be34bf7d73334f11c2dba to your computer and use it in GitHub Desktop.
Save Gomi-coder/6c69733c623be34bf7d73334f11c2dba to your computer and use it in GitHub Desktop.
find() vs index()
## 공통점
# 둘 다 찾은 첫 번째 자리를 출력
'asdf문자열'.find('d')
'asdf'.index('d')
#시작점, 종료점 지정 (찾을 문자열, 시작점, 종료점) 혹은 (찾을 문자열, 시작점)
'asdfasd'.index('d', 2)
'asdfasdf'.find('d',1,3)
## 차이점
'hello'.find('o',1,3) #찾는 값 없으면 -1
'hello'.index('o',1,3) #찾는 값 없으면 ValueError
#find는 문자열만
#index는 딕셔너리 빼고(문자열, 리스트, 튜플)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment