[Tutor] searching for a value in an array

Erik Price erikprice@mac.com
Thu, 5 Sep 2002 15:26:28 -0400


On Thursday, September 5, 2002, at 02:32  PM, anthony polis wrote:

> How do you search for a value in an array? For example:
>
> I need to check to see if the string "bob" is in the array "people".

To pick nits, Python doesn't have arrays -- it has List objects.

 >>> strings = ['one', 'two', 'three']
 >>> if ('one' in strings): print "Yes"
... else: print "No"
...
Yes
 >>> if ('four' in strings): print "Yes"
... else: print "No"
...
No




Erik





--
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org