in string

Emile van Sebille emile at fenx.com
Thu Nov 1 11:52:57 EST 2001


"Jeff Sandys" <sandysj at juno.com> wrote in message
news:3BE17AFD.1655EEF8 at juno.com...
> I kind of understand why this (below) doesn't work.
> What would you have to do to make it work?
> (to make 'eggs' in 'spam and eggs' return 1)
> Or what does: string member test needs char left operand
> mean?
>
> Python 1.5.2 (#2, Apr  4 2000, 13:12:48) [C] on aix4
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> a = 'spam and eggs'
> >>> 'e' in a
> 1
> >>> 'eggs' in a
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> TypeError: string member test needs char left operand
> >>>
>

import string
string.find(a, 'eggs')

Note:  this can return 0 (as in 'eggs and eggs');
-1 is the not found return value

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list