namespace issue?

Chris Barker chrishbarker at home.net
Fri Jun 22 12:28:17 EDT 2001


Michael Powe wrote:

> So now the question is, 'why'?  Am I misusing the string.find()
> function? Okay, string.find() returns -1 when the string is not found,
> which would seem to be what I expected, a false result.  Maybe python
> doesn't treat -1 as false? 

Even if it did, you wouldn't want to do :

if not s.find():

because find() returns a zero if the sting you are looking for is at the
beginning of the string. Zero is definitely a false value.

>>> s = "abc"
>>> s.find('a')
0

so you need to test for the -1 in any case.

-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