Created
February 15, 2023 01:12
-
-
Save Gomi-coder/6c69733c623be34bf7d73334f11c2dba to your computer and use it in GitHub Desktop.
find() vs index()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 공통점 | |
# 둘 다 찾은 첫 번째 자리를 출력 | |
'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