[Tutor] find('') returns 0

eryksun eryksun at gmail.com
Mon Sep 17 02:57:31 CEST 2012


On Sun, Sep 16, 2012 at 8:33 PM, eryksun <eryksun at gmail.com> wrote:
>
> The 'in' operator also searches for a substring:
>
>     >>> '' in 'abc'
>     True

I forgot to mention, this use of slices is a peculiarity to strings.
In contrast, list.index and list.__contains__ ("in") match against
individual items. An empty list slice [] is not "in" ['a', 'b', 'c'].
Be careful about this use of substrings:

    >>> 'care' in 'careful programming'
    True
    >>> 'care' in 'careful programming'.split()
    False


More information about the Tutor mailing list