Computer Science, asked by sjnmarketz1545, 9 months ago

Write source in Python code for membership operators.

Answers

Answered by poojan
2

Python Membership operators

in - returns True, if element is found

not in - returns True, if element is not found

is - return True, if the element is same as the comparative one

is not - returns True, if the element is not same as the comparative one

Let us see their functioning with an example :

For in and not in operators :

Code :

a=2

b=3

x=[34,57,7,75,23]

print(a in x)         #returns False as 2 is not in x

print(b not in x)  #returns True as 3 is not in x

print(75 in x)       #returns True as 75 is present in x

print(23 not in x) #returns False as 23 is in x

Output :

False

True

True

False

For is and is not operators :

Code :

c='axy'

d=3

print(c is 'gef')      #returns False as both the strings aren't same

print(d is not 3.0) #returns True  as 3 and 3.0's types are different

print(c is 'axy')      #returns True as both are same

print(d is not 3)    #returns False as both are same

Output :

False

True

True

False

Python membership operators are widely used in searching an element from iterables or in making the comparisions of left operand with the right one.

  • They are also oftenly use in performing actions through conditional statements or ranged loops.

  • Python has 4 membership operators : in, not in, is, is not

  • 'in' operator is used check for a value in iterables

  • Checking value is directly compared with the values of the iterables and their types.

  • They are of boolean types. Returns either True or False based on the computed resultant.

Learn more :

1) Python program for conversion of height from cm to inches

     brainly.in/question/12368676

2) Rules for writing an algorithm.

      brainly.in/question/5243751

Attachments:
Similar questions