sorry, i'm beginner python. want see list item in. have lists set like:
l1 = [1,2,3] l2 = [4,5,6] l3 = [7,8,9]
and let's want find list item 5 in. i'm doing is:
if l1.index(5)!=false: print 1 elif l2.index(5)!=false: print 2 elif l3.index(5)!=false: print 3
but doesn't work. how this?
you can use in
operator check membership:
>>> 5 in [1, 3, 4] false >>> 5 in [1, 3, 5] true
Comments
Post a Comment