in string

Chris Barker chrishbarker at home.net
Thu Nov 1 14:25:08 EST 2001


Emile van Sebille wrote:
> > 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?

It means that the "in" operator tries to look for an item in a sequence
of items. A string is a sequence of single charactors, so to use x in
string, x must be a single character.

> import string
> string.find(a, 'eggs')
> 
> Note:  this can return 0 (as in 'eggs and eggs');
> -1 is the not found return value

or, in recent pythons:

>>> a = 'spam and eggs'
>>> a.find('eggs')
9

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list