I don't quite get this "string".find()

Isaac To iketo2 at netscape.net
Thu Nov 11 19:57:46 EST 2004


>>>>> "Jaime" == Jaime Wyant <programmer.py at gmail.com> writes:

    Jaime> Will someone explain this to me?
    >>>> "test".find("")
    Jaime> 0

    Jaime> Why is the empty string found at position 0?

It is completely natural.  "test".find("es") = 1 because 1 is the
smallest x such that "test"[x:x+len("es")] == "es" (i.e., the smallest
x such that the substring of "test" from position x starts with "es").
Now what is the smallest x such that "test"[x:x+len("")] == ""?

Regards,
Isaac.



More information about the Python-list mailing list