Skip to content

Computer Science · Ch 10 — Tuples and Dictionaries

Membership

10.2.3

Membership

The membership operators test whether a value occurs among a tuple's elements.

The in operator

in checks if the element is present in the tuple. It returns True when the element is found, and False otherwise:

>>> colours = ('Red', 'Green', 'Blue')
>>> 'Green' in colours
True

The not in operator

not in is the logical opposite: it returns True if the element is not present in the tuple, else it returns False:

>>> colours = ('Red', 'Green', 'Blue')
>>> 'Green' not in colours
False
``` …