Perl to Python: Subroutines & Functions
Subroutines
<i> Contrary to Perl you first need to have a subroutine declared before you can use it. So the defs are the first thing in your script. Then comes the main part. When calling one def from another def the order does not matter.
Arguments with =... are optional:
- def foobar(object, spacing=10, collapse=1):
Arguments can be given in any order:
- foobar(spacing=20, object=blah)
Multiple arguments can be passed as a tuple:
- def foobar(a, b, *list): ...
Unpack a list before sending it to a subroutine:
- list = [1, 2, 3] foobar(*list)
Print the first comment (“““ Blah “““) of a subroutine:
print foobar.__doc__
