How to check if a list contains an item

Tim Chase python.list at
Sun Apr 12 21:38:02 CEST 2009 at wrote:
> python doesn't have a list.contains()   method?

Because it doesn't need one?

   >>> x = [1,2,3,4]
   >>> 2 in x
   >>> 42 in x

pedantic side-note, objects can have a __contains__ method which 
is used under the covers for "in" testing, so your custom objects 
can also test for containment.


More information about the Python-list mailing list