Python Forum

Full Version: dynamic arguments list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
if i make a list and call a function with it, like:
foo = [0,1,2,3,4,5]
myfun(*foo)
and the function is coded like:
def myfun(*args):
is the function always going to get args as a tuple instead of the original list?
If you call the function as myfun(*foo), then the list foo isn't passed and the function can't do anything to receive it.

Instead, the list is unpacked and only the elements are passed along. The original list is not sent and cannot be received.

The star argument in the definition does mean that all the arguments will appear in a tuple.
what i ultimately want to know is: is there any possible way that function might be called which would give it something other than a tuple. the example i used was what i thought might be the most likely. my concern is within the function. can it always assume that it will always be given a (possibly empty) tuple. if i concatenate it with a literal tuple value, is that safe?
From everything I have read, and from all my experiments, *args is always a tuple to the function