0% found this document useful (0 votes)
3 views2 pages

Membership Operators

Uploaded by

anwithadata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Membership Operators

Uploaded by

anwithadata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

=============================================

6. Membership Operators
=============================================
=>The purpose of membership operators is that "To Check whether the Specific Value
present in Iterable object Or Not".
=>An Iterable object is one, which contains More Number of Values
(Examples: Sequence Type,List Type,Set type,Duct type)
=>In Python Programming, we have 2 types of Membership Operators. They are
1. in
2. not in
-----------------------------------------------------------------------------------
------------------------------------------------------
1. in
-----------------------------------------------------------------------------------
------------------------------------------------------
Syntax: Value in IterableObject
-----------
=>"in" operator returns True Provided Value present in Iterable object
=>"in" operator returns False Provided Value not present in Iterable object
-----------------------------------------------------------------------------------
------------------------------------------------------
2. not in
-----------------------------------------------------------------------------------
------------------------------------------------------
Syntax: Value not in IterableObject
-----------
=>"not in" operator returns True Provided Value not present in Iterable object
=>"not in" operator returns False Provided Value present in Iterable object
-----------------------------------------------------------------------------------
------------------------------------------------------
Examples:
-----------------------------------------------------------------------------------
------------------------------------------------------
>>> s="PYTHON"
>>> print(s,type(s))------------PYTHON <class 'str'>
>>> "P" in s---------------------True
>>> "O" in s--------------------True
>>> "O" not in s--------------False
>>> "K" in s-------------------False
>>> "K" not in s--------------True
>>> "p" in s--------------------False
>>> "p" not in s--------------True
---------------------------------------------------------------
>>> s="PYTHON"
>>> print(s,type(s))--------------PYTHON <class 'str'>
>>> "PYT" in s-------------------True
>>> "PYTH" not in s-----------False
>>> "PYTH" in s-----------------True
>>> "THON" not in s------------False
>>> "THON" in s----------------True
>>> s="PYTHON"
>>> print(s,type(s))-------------PYTHON <class 'str'>
>>> "PON" in s------------------False
>>> "HON" in s------------------True
>>> "PON" not in s-------------True
>>> "NOH" in s-----------------False
>>> "NOH" not in s------------True
>>> "PTO" in s-----------------False
>>> s="PYTHON"
>>> print(s,type(s))---------------PYTHON <class 'str'>
>>> "NOH" in s[::-1]---------------True
>>> "PTO" not in s[::2]----------False
>>> "PTO" in s[::2]---------------True
>>> "OTP" not in s[1::-2]----------True
>>> s[1::-2]-----------------------------'Y'
--------------------------------------------------------------
>>> lst=[10,"Rossum",True,2+3j]
>>> print(lst,type(lst))----------------[10, 'Rossum', True, (2+3j)] <class 'list'>
>>> 10 in lst-----------------------------True
>>> True not in lst----------------------False
>>> 2+3j in lst---------------------------True
>>> "Ros" in lst------------------------False
>>> "Ros" in lst[1]-------------------True
>>> "mus" not in lst[1][::-1]---------False
>>> lst[::-1] not in lst[::]---------------True
>>> lst[1][::-1] in lst[::]----------------False
>>> lst[1][::-1] in lst[-3][::-1][::-1]-----False
-------------------------------------------------------------------
>>> lst=[10,"Rossum",True,2+3j]
>>> print(lst,type(lst))-------------------------[10, 'Rossum', True, (2+3j)]
<class 'list'>
>>> 2+3j in lst----------------------------------True
>>> 2+3j not in lst----------------------------False
-------------------------
>>> 2 in lst[-1]---------------------TypeError: argument of type 'complex' is not
iterable
>>> 3 in lst[-1].imag------------TypeError: argument of type 'float' is not
iterable
------------------------------------------------------------------------
>>> d1={10:"Python",20:"Java",30:"C++"}
>>> print(d1,type(d1))---------------{10: 'Python', 20: 'Java', 30: 'C++'} <class
'dict'>
>>> 10 in d1----------------True
>>> 30 not in d1-----------False
>>> 40 in d1----------------False
>>> "Python" in d1---------False
>>> "Python" in d1[10]----True
>>> "C++" in d1.get(30)---------True
>>> "C++"[::-1] not in d1.get(30)[::-1]----False
>>> "C++"[::-1] in d1.get(30)[::-1]---------True
==============================x===============================================

You might also like