7.3. Logical operators

The three logical operators not, and and or enable you to compose boolean expressions and by this way to construct more complex conditions. Here are some examples:

>>> seq =  'ATGCnATG'
>>> 'n' in seq or 'N' in seq
True
>>> 'A' in seq and 'C' in seq
True
>>> 'n' not in seq
False
>>> len(seq) > 100 and 'n' not in seq
False
>>> not len(seq) > 100
True
     

Caution

The or operation is not an exclusive or as it is sometimes used in the current languages. An or expression is also true if both subexpressions are true.

>>> seq = 'ATGCnATG'
>>> 'A' in seq or 'C' in seq
True