[Python] find(), index() with str

숭글·2023년 2월 3일
0

find()

str.find(sub[, start[, end]])

  • sub : 찾을 문자
  • start(opional) : 시작 인덱스
  • end(optional) : 끝 인덱스

str에서 처음으로 발견된 sub의 인덱스를 반환한다.
start, end에 값이 있는 경우 슬라이스 notation을 따르게 된다.
str에 sub가 존재하지 않는다면 -1을 반환한다.

index()

str.index(sub[, start[, end]])

  • sub : 찾을 문자
  • start(opional) : 시작 인덱스
  • end(optional) : 끝 인덱스

str에서 처음으로 발견된 sub의 인덱스를 반환한다.
start, end에 값이 있는 경우 슬라이스 notation을 따르게 된다.
str에 sub가 존재하지 않는다면 ValueError가 발생한다.


📖 docs<find>
📖 docs<index>

profile
Hi!😁 I'm Soongle. Welcome to my Velog!!!

0개의 댓글