[Tutor] index and find

Terry Carroll carroll at tjc.com
Sun Oct 23 05:17:46 CEST 2005

On Sat, 22 Oct 2005, Shi Mu wrote:

> what is the difference between index and find in the module of string?
> for both "find" and "index", I got the position of the letter.

index raises a ValueError if the string isn't found:

>>> s = "spam"
>>> s.find('m')
>>> s.index('m')
>>> s.find('z')
>>> s.index('z')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: substring not found

More information about the Tutor mailing list