Chapter 13. Functions II

Table of Contents

13.1. Passing argument by name
13.2. Defining default values
13.3. Variable number of parameters
13.4. Functions and namespaces
13.5. Defining a function as a parameter

In Section 8.1 we have learnt how to define functions. In this chapter we introduce new mechanims for parameter definition and passing. We also present a new way to use functions.

13.1. Passing argument by name

Up to now, we have called functions by passing arguments in the order that was specified by the definition of the function:

def isunique(str, motif):
    nb = count(str, motif)
    if nb != 1:
       return False
       return True

seq = "..."
BamHI   = 'GGATCC'
print isunique(seq, BamHI)
This is called passing arguments by position. It is also possible to pass arguments by name:
print isunique(str=seq, motif=BamHI)
or, since the order is no longer required:
print isunique(motif=BamHI, str=seq)
You can mix either style, but named argument must be put after positioned arguments.
print isunique(seq, motif=BamHI)