|
| 1 | +#!/usr/bin/env python |
| 2 | +"""Does... |
| 3 | +
|
| 4 | +Created on Aug 25, 2011 |
| 5 | +
|
| 6 | +@author: paulross |
| 7 | +""" |
| 8 | + |
| 9 | +__author__ = 'Paul Ross' |
| 10 | +__date__ = '2011-08-03' |
| 11 | +__version__ = '0.1.0' |
| 12 | +__rights__ = 'Copyright (c) 2011 Paul Ross.' |
| 13 | + |
| 14 | +################################### |
| 15 | +# The many ways of calling parrot() |
| 16 | +################################### |
| 17 | +def parrot(voltage, |
| 18 | + state='a stiff', |
| 19 | + action='voom', |
| 20 | + type='Norwegian Blue'): |
| 21 | + print "-- This parrot wouldn't", action, |
| 22 | + print "if you put", voltage, "volts through it." |
| 23 | + print "-- Lovely plumage, the", type |
| 24 | + print "-- It's", state, "!" |
| 25 | + |
| 26 | +def main(): |
| 27 | + parrot(1000) |
| 28 | + print |
| 29 | + parrot(action='VOOOOOM', voltage=1000000) |
| 30 | + print |
| 31 | + parrot('a thousand', state='pushing up the daisies') |
| 32 | + print |
| 33 | + parrot('a million', 'bereft of life', 'jump') |
| 34 | + print |
| 35 | + # These will raise a SyntaxError |
| 36 | +# parrot() # required argument missing |
| 37 | +# parrot(voltage=5.0, 'dead') # non-keyword argument following keyword |
| 38 | + parrot(110, 'a', 'b', voltage=220) # duplicate value for argument |
| 39 | +# parrot(actor='John Cleese') # unknown keyword |
| 40 | + |
| 41 | +if __name__ == '__main__': |
| 42 | + main() |
| 43 | + |
| 44 | +######################################## |
| 45 | +# END: The many ways of calling parrot() |
| 46 | +######################################## |
0 commit comments