[Tutor] Example 1

Gonçalo Rodrigues op73418@mail.telepac.pt
Wed Dec 11 07:41:02 2002


----- Original Message -----
From: "Adam Vardy" <anvardy@roadrunner.nf.net>
To: <tutor@python.org>
Sent: Wednesday, December 11, 2002 12:29 PM
Subject: Re: [Tutor] Example 1


>
> Wednesday, December 11, 2002, 5:40:11 AM, you wrote:
>
> >> But sometimes you don't know how many arguments to expect.
> >> Then you can use the *-form, like this:
>
> >> In other words, we expect that the function call looks something like
> >> "union([1,4,6],(5,6,4),[2,3,4])" or perhaps "union('strings','are',
>
> Sure then. So how does the program logic know where are the 1 4 6 and
> the other numbers? And tell them apart?

Consider the following

>>> def testargs(*args):
...  print args
...
>>> testargs(1, 2, 3, 4)
(1, 2, 3, 4)

As you can see, when you include *args in our function definition, the
arguments passed are collected in a tuple. You can now refer to them as
args[0], args[1], etc.

>
> --
> Adam Vardy
>

HTH,
G. Rodrigues