Spencer Pearson wrote:
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?
FYI some linters report the usage of * as bad practice, I don't know the reason though. Pylint reports it as using 'magic'.
Anyway the form without * is commonly used.

JM
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to