Function Details: index_(str)

Description

Returns the lowest index where the substring is found.

Extended Description

index is a Python string method that finds first occurrence of substring and returns its position. Similar to find but raises ValueError when substring not found, making it stricter. Works with rindex for searching from right side. Accepts optional start and end parameters for search range. Partners with split and partition for text parsing. Often used when substring must exist, making error handling explicit. Essential for string validation and strict text processing workflows.


Function Signature


str.index(sub: str, start: int = 0, end: int = None) -> int

Module: str

Class: str

Parameters



Parameter List


  • sub: str
  • start: int
  • end: int

Return


Returns an integer representing the lowest index where the substring is found.


Return Type


int

Output

Explanation

This example shows finding the index of substrings in the string.