Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamic arguments list
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
buran likes this post
Reply
#3
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
From everything I have read, and from all my experiments, *args is always a tuple to the function
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 3,819 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020