I have a function (which I'll call foo) that modifies a list (which I'll call my_list). foo does not always want to modify my_list in the same way; its behavior should influenced by its other arguments (which I'll call other_inputs). Here's some pseudocode:
def foo(my_list, other_inputs):
for input in other_inputs:
my_list.bar(input)
return my_list
I can see two ways to format other_inputs.
I could use *args:
def foo(my_list, *other_inputs):
for input in other_inputs:
my_list.bar(input)
return my_list
Alternately, I could make other_inputs a list, empty by default:
def foo(my_list, other_inputs=[]):
for input in other_inputs:
my_list.bar(input)
return my_list
I've tested it on my machine and both options seem to do the same thing. Which one is preferable?
(Assume that this foo() is called many times, each time with a new other_inputs read in from some external source. Also assume that other_inputs is never appended to or mutated in any other way between external reads, so this isn't a problem.)