Python "member of" function
Erik Max Francis
max at alcyone.com
Sat Apr 29 06:38:11 EDT 2006
brianlum at gmail.com wrote:
> I was wondering if anyone knew of a built in Python function that will
> check if an item is a member of a list, i.e., if item i is a member of
> list l.
>
> I read of a function "in" but I can't seem to get that to work and
> finding pages for "python in" does not reveal very many relevant
> sources.
Yes, `in` is the relevant operator. It's quite simple to use:
>>> a = [1, 4, 9, 16, 25]
>>> 2 in a
False
>>> 4 in a
True
If you're having problems using it in some circumstance, you'll have to
be specific.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
No man quite believes in any other man.
-- H.L. Mencken
More information about the Python-list
mailing list