__contain__() in python by R4R Team

- __contain__() is a python function which search the item in the given list and on this basis it return the True or False.

Syntax-

list.__contain__(item)

-It will return True if item is present in the list
-It will return Fasle if item is not in the given list.

Example

list is [1,2,3]
list.__contain__(3) will return True.
list.__contain__(8) will return False.


program-

l=[1,2,3,"one","two"]
print(l.__contains__(2))
print(l.__contains__(2))
print(l.__contains__(6))
print(l.__contains__("one"))


output-

True
True
False
True


-In this program, we have a list [1,2,3,"one","two"], then we find the items in list by __contain__() and print returned value one by one.
- Like, l.__contain__("one") will return True because "one" is present in the given list.




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!