Main.TupleVarArgs History
Hide minor edits - Show changes to markup
March 23, 2010, at 11:13 PM MST
by -
Added lines 1-35:
(:source lang=python:)
""" Variable length function argument lists """
- In some cases it will be useful for a function to be able to
- handle an arbitrary number of arguments.
- 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)
- let's call this function:
- you can call it with a single argument:
tuple_var_args('one')
- or two:
tuple_var_args('one', 'two')
- note that in the above two calls the tuple of additional
- arguments is empty
- when we use more than two arguments any additional argument
- is stored in the tuple:
tuple_var_args('one', 'two', 'three', 'four')
(:sourceend:)
