Monday 13 March 2023

Membership Operatos

 Membership Operators

The Membership operators that are present in the python are:
  1. in operator
  2. not in operator

in operator

The in membership operator checks whether the specified value is present in the sequence or not. If the value is available in the sequence then it returns True. If the specified value is not available in the sequence then it returns False.


list=[1,4,6,8,11]
if(11 in list):
    print("11 is available in the list")
else:
    print("11 is not available in the list")
Output
11 is available in the list

not in operator

The membership operator not in checks whether is not in the sequence or not. If the specified value is not in the list then it returns True. If the specified value is in the list then it returns False.

list=[1,4,2,4,6,8,7,9,7,8,6]
list1=[]
for i in list:
    if(i not in list1):
        list1.append(i)

print(list1)
Output
[1, 4, 2, 6, 8, 7, 9]

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top