7.4. Alternative execution

If the condition of a if statement is not fulfilled no statement is executed.

>>> seq = 'ATGACGATAG'
>>> if 'n' in seq:
	print "sequence contains undefined characters"
>>>
      

An alternative sequence of statements, that will be executed if the condition is not fulfilled, can be specified with the else statement.

>>> seq = 'ATGACGATAG'
>>> if 'n' in seq:
...    print "sequence contains undefined bases"
... else:
       print "sequence contains only defined bases"
sequence contains only defined bases
      

Here the if and else are followed by a block containing the statements to execute depending on the truth value of the condition. In this case exactly one of them is executed, which is illustrated in Figure 7.4

Figure 7.4. Flow of execution of an alternative condition