[Tutor] index and find

Kent Johnson kent37 at tds.net
Sun Oct 23 13:22:37 CEST 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.

Chapter 2 of the Library Reference is a wealth of information about built-in types:
http://docs.python.org/lib/builtin.html

In particular this page
http://docs.python.org/lib/string-methods.html

which says
find(  	sub[, start[, end]])
    Return the lowest index in the string where substring sub is found, such that sub is contained in the range [start, end). Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found. 

index( 	sub[, start[, end]])
    Like find(), but raise ValueError when the substring is not found. 

Kent



More information about the Tutor mailing list