How to check whether a list have specific value exist or not?

Michael Hoffman cam.ac.uk at mh391.invalid
Sat Apr 9 05:46:13 EDT 2005


praba kar wrote:

> In Php we can find in_array() function
> which function is mainly useful to check
> whether a specific value is exist in the array
> or not.
> 
> But In python In cannot find any function
> like that.

If you just want a boolean result you can use x in l:

 >>> l = range(5)
 >>> l
[0, 1, 2, 3, 4]
 >>> 3 in l
True
 >>> 42 in l
False
-- 
Michael Hoffman



More information about the Python-list mailing list