contains() in operator module in python by R4R Team

- contains() is a python in-build function which check the item present in sequence or not.

Syntax-

operator.contains(seq,item)

-Here seq is sequence, i.e. list,tuple etc
-It check item is present in sequence or not.
-If item is present in sequence then it return True otherwise return False.

Example-
list is l:[1,2,3]
operator.contains(l,2) will return True
operator.contains(l,4) will return false


program-

import operator
l=[1,2,3]
t=(1,2,3)
print(operator.contains(l,3))
print(operator.contains(l,1))
print(operator.contains(l,4))
print(operator.contains(t,6))
print(operator.contains(t,'a'))
print(operator.contains(t,2))


output-

True
True
False
False
False
True


-In this program, we import the operator module by import operator, so that we can call the contains() function.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!