Membership Operators


This code defines a list of fruits called 'fruits' containing 'apple', 'orange', and 'grapes' as elements. It then uses the membership operator 'in' to check if the string 'apple' is present in the list 'fruits'. If it is present, it will print "Apple available in our fruit list". If it is not present, it will print "Apple not available in our fruit list".

Source Code : 1

fruits	=['apple','orange','grapes']

print("Membership Operator IN Example")
#IN EXAMPLE
if('apple' in fruits):
   print("Apple available in our fruit list")
else:
   print("Apple not available in our fruit list")
To download raw file Click Here

Output : 1

Membership Operator IN Example

Apple available in our fruit list

This code defines a list of fruits called 'fruits' containing 'apple', 'orange', and 'grapes' as elements. It then uses the membership operator 'not in' to check if the string 'banana' is not present in the list 'fruits'. If it is not present, it will print "Banana not available in our list". If it is present, it will print "Banana available in our list".

Source Code : 2

fruits	=['apple','orange','grapes']

print("Membership Operator Not IN Example")

#NOT IN EXAMPLE
if('banana' not in fruits):
   print("Banana not available in our list")
else:
    print("Banana available in our list")
To download raw file Click Here

Output : 2

Membership Operator Not IN Example

Banana not available in our list