Re: I don't quite get this "string".find()
From: Tim Peters (tim.peters_at_gmail.com)
Date: 11/11/04
- Next message: Caleb Hattingh: "Re: I don't quite get this "string".find()"
- Previous message: Caleb Hattingh: "Re: Concise idiom to initialize dictionaries"
- Maybe in reply to: Jaime Wyant: "I don't quite get this "string".find()"
- Next in thread: Caleb Hattingh: "Re: I don't quite get this "string".find()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 11 Nov 2004 15:12:51 -0500 To: python-list@python.org
[Jaime Wyant]
> Ahh, I see it now. It seems strange to me, but your find helped make
> sense of it.
Indeed, the only way to have "test".find("") *not* return 0 would be
to make a special case out of searching for an empty string. If you
don't make a special case of it, 0 seems to be the necessary result.
> I guess I thought:
>
> 1) an empty string is like "nothing"
> 2) you can never find "nothing" in something
>
> But I guess an empty string isn't nothing, but a string with no
> length. Ahh, it's still darned strange :).
Consistency and strangeness often go together <0.7 wink>. I find this
particular one ("every string starts with an empty string") strangest
in this context:
>>> "a" in "abc"
True
>>> "c" in "abc"
True
>>> "d" in "abc"
False
>>> "" in "abc"
True
In practice, my solution is not to search for empty strings <wink>.
- Next message: Caleb Hattingh: "Re: I don't quite get this "string".find()"
- Previous message: Caleb Hattingh: "Re: Concise idiom to initialize dictionaries"
- Maybe in reply to: Jaime Wyant: "I don't quite get this "string".find()"
- Next in thread: Caleb Hattingh: "Re: I don't quite get this "string".find()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|