Python Membership Operators Example

Rate this post

Example:

#!/usr/bin/python

a = 10
b = 20
list = [1, 2, 3, 4, 5 ];

if ( a in list ):
print “Line 1 – a is available in the given list”
else:
print “Line 1 – a is not available in the given list”

if ( b not in list ):
print “Line 2 – b is not available in the given list”
else:
print “Line 2 – b is available in the given list”

a = 2
if ( a in list ):
print “Line 3 – a is available in the given list”
else:
print “Line 3 – a is not available in the given list”

Output:

Line 1 – a is not available in the given list
Line 2 – b is not available in the given list
Line 3 – a is available in the given list

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: