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

Membership Operators

The document explains membership operators in Python, which are used to check the existence of a value in iterable objects. It describes two operators: 'in' returns True if a value is present in an iterable, while 'not in' returns True if a value is absent. Examples illustrate the usage of these operators with various iterable and non-iterable objects.
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)
21 views2 pages

Membership Operators

The document explains membership operators in Python, which are used to check the existence of a value in iterable objects. It describes two operators: 'in' returns True if a value is present in an iterable, while 'not in' returns True if a value is absent. Examples illustrate the usage of these operators with various iterable and non-iterable objects.
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

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

Membership Operators
===============================================================
=>The Purpose of Membership Operators is that "To Check the Existence of in
Iterable Object".
=>An Iterable Object is one, which contains More than One Values
Examples: str,bytes,bytearray,range,list,tuple,set,frozenset,dict
=>A Non-Iterable Object is one, which contains Only One Value
Examples: int,float,bool,complex,NoneType.
=>In Python Programming, we have Two Membership Operators. They are
1. in Operator
2. not in Operator
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
1. in Operator
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
=>Syntax: Value in Iterable-Object
=>Here 'in' Operator Returns True Provided 'Value' Present in Iterable Object.
=>Here 'in' Operator Returns False Provided 'Value' not Present in Iterable Object.
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
2. not in Operator
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
=>Syntax: Value not in Iterable-Object
=>Here 'not in' Operator Returns True Provided 'Value' not Present in Iterable
Object.
=>Here 'not in' Operator Returns False Provided 'Value' Present in Iterable Object.
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
Examples
-----------------------------------------------------------------------------------
------------------------------------------------------------------------
>>> s="PYTHON"
>>> "P" in s
True
>>> "K" in s
False
>>> "ON" in s
True
>>> "NO" in s
False
>>> "NO" in s[::-1]
True
>>> "NO" not in s[::-1]
False
>>> "PYT" in s
True
>>> "PTO" in s
False
>>> "PTO" in s[::2]
True
>>> lst=[100,"Rossum",23.45,2+3j]
>>> 100 in lst
True
>>> "Ros" in lst
False
>>> "Ros" in lst[1]
True
>>> 2+3j in lst[-1]--------------------------TypeError: argument of type 'complex'
is not iterable
>>> 2.0 in lst[-1].real---------------------TypeError: argument of type 'float' is
not iterable
>>> "muss" in lst[1][::-1]-----------------True
-----------------------------------------------------------------------------------
------------------------------------------------------------------------

You might also like