choco's story

파이썬 스터디 8 - find() & rfind() 함수 본문

프로그래밍 언어 공부 (Coding Study)/파이썬 (Python) 기본

파이썬 스터디 8 - find() & rfind() 함수

초코choco 2024. 9. 18. 13:12

 find() & rfind() 함수

해당 문자열이 몇 번째에 위치하고 있는지를 알려주는 함수

  • find() : 왼쪽부터 찾아서 처음 등장하는 위치 확인
  • refind() : 오른쪽부터 찾아서 처음 등장하는 위치 확인

ex)

string_a = "HelloHelloHelloPython".find("Hello")
print(string_a)
string_b = "HelloHelloHelloPython".rfind("Hello")
print(string_b)

출력결과