Why does Python show the whole array?

Ulrich Eckhardt eckhardt at satorlaser.com
Wed Apr 8 12:11:55 CEST 2009


Gilles Ganault wrote:
> test = "toto at gmail.com"
> isp = ["gmail.com", "yahoo.com"]
> for item in isp:
> if test.find(item):
> print item
> ======= output
> gmail.com
> yahoo.com
> =======
> 
> Any idea why I'm also getting "yahoo.com"?

find() returns the index where it is found or -1 if it is not found. Both an
index>0 or a -1 evaluate to True when used as conditional expression.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list