Inclusion Operators
Contents
Inclusion Operators#
Inclusion operators are used to check if a value/object is in a collection and return boolean values.
in
#
The in
operator returns a True
if the left value/object is in the collection on the right and False
if it is not:
print(1 in [0, 1, 2, 3])
True
print('a' in 'abc')
True
print(2.4 in [1, 2, 3])
False
not in
#
The not in
operator returns the converse of the in
operator:
print('a' not in 'abc')
False
print(7 not in [1, 2, 3, 4, 5])
True