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

Caleb Hattingh caleb1 at telkomsa.net
Thu Nov 11 22:28:46 EST 2004


Hi Jaime

I don't know why the function was set up this way.  However, an empty  
string can be found in an infinite number of places within any other  
string.  It is a difficult situation, like dividing zero into a nonzero  
number.  (Are you asking why it specifically returns 0 and not INF or an  
exception...?)

If you want to match a *blank*, you gotta do

>>> "test".find(" ") # There is a space between the last two ""s
-1
>>> _

but I expect you are aware of this and this was not your question.  Also,  
if you want to check whether a string is empty, I do

>>> "test" == ""
False
>>> _

One of the gurus can probably answer you better than I.

thx
Caleb


On Thu, 11 Nov 2004 13:36:41 -0600, Jaime Wyant <programmer.py at gmail.com>  
wrote:

> Will someone explain this to me?
>
>>>> "test".find("")
> 0
>
> Why is the empty string found at position 0?
>
> Thanks!
> jw




More information about the Python-list mailing list