By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

passing variable arguments to a function

P: n/a
Hello all,

I want to be able to pass a variable number of parameters into a Python
function. Now, I know how to _receive_ variable arguments, but I don't
know how to _send_ them.

def myFunction(*args):
print args

myList = [1, 2, 3, 4]
myFunction(myList)

this function will print out ([1, 2, 3, 4]).

Except that's not what I want. I want the equivalent to:

myFunction(1, 2, 3, 4)

So, given an array, how can I unpack the array and pass all of the
elements into a Python function as parameters?

Thanks in advance!,
_Ryan Wilcox

Oct 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ryan Wilcox a écrit :
Hello all,

I want to be able to pass a variable number of parameters into a Python
function. Now, I know how to _receive_ variable arguments, but I don't
know how to _send_ them.

def myFunction(*args):
print args

myList = [1, 2, 3, 4]
myFunction(myList)

this function will print out ([1, 2, 3, 4]).

Except that's not what I want. I want the equivalent to:

myFunction(1, 2, 3, 4)

So, given an array, how can I unpack the array and pass all of the
elements into a Python function as parameters?

Thanks in advance!,
_Ryan Wilcox


myFunction(*myList)
Oct 13 '05 #2

P: n/a
Ryan Wilcox wrote:
I want to be able to pass a variable number of parameters into a Python
function. Now, I know how to _receive_ variable arguments, but I don't
know how to _send_ them.

def myFunction(*args):
print args

myList = [1, 2, 3, 4]
myFunction(myList)

this function will print out ([1, 2, 3, 4]).

Except that's not what I want. I want the equivalent to:

myFunction(1, 2, 3, 4)

So, given an array, how can I unpack the array and pass all of the
elements into a Python function as parameters?


same syntax:

myFunction(*myList)

</F>

Oct 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.