Main.TupleVarArgs History

Hide minor edits - Show changes to markup

March 23, 2010, at 11:13 PM MST by 71.196.160.210 -
Added lines 1-35:

(:source lang=python:)

""" Variable length function argument lists """

  1. In some cases it will be useful for a function to be able to
  2. handle an arbitrary number of arguments.
  3. These are called variable length arguments lists.

def tuple_var_args(arg1, arg2 = 'defaultB', *the_rest) :

    print 'formal arg1:', arg1
    print 'formal arg2:', arg2
    print 'the rest:', str(the_rest)
    print 'the type of the type(the_rest)', type(the_rest)
  1. let's call this function:
  2. you can call it with a single argument:

tuple_var_args('one')

  1. or two:

tuple_var_args('one', 'two')

  1. note that in the above two calls the tuple of additional
  2. arguments is empty
  3. when we use more than two arguments any additional argument
  4. is stored in the tuple:

tuple_var_args('one', 'two', 'three', 'four')

(:sourceend:)