In [1]:

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

2025-05-29 13:18

Returns the index of the substring or raises an error.

### index(sub[, start[, end]])

**Description:**
Returns the index of the first occurrence of the substring. Raises ValueError if not found.

**Example:**
“`python
text = “hello”
print(text.index(“e”)) # Output: 1
“`

**Use Case:**
Like find(), but ensures the substring exists by raising an error if it doesn’t.