Tuples vs. variable-length argument lists

Spencer Pearson speeze.pearson at gmail.com
Fri Mar 19 20:20:31 EDT 2010


Hi!
This might be more of a personal-preference question than anything,
but here goes: when is it appropriate for a function to take a list or
tuple as input, and when should it allow a varying number of
arguments? It seems as though the two are always interchangeable. For
a simple example...
def subtract( x, nums ):
 return x - sum( nums )
... works equally well if you define it as "subtract( x, *nums )" and
put an asterisk in front of any lists/tuples you pass it. I can't
think of any situation where you couldn't convert from one form to the
other with just a star or a pair of parentheses.
Is there a generally accepted convention for which method to use? Is
there ever actually a big difference between the two that I'm not
seeing?


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /