PythonStringindex

Returns the index of the first occurrence of a substring (raises ValueError if not found).

Syntax

str.index(sub, start?, end?)

Example

Enter values below to update the example in real time.

print
index
ValueError
text = "Hello World"
print(text.index("World"))  # 6
# text.index("Python")  # ValueError