### Thread: Function Parameter

1. #### Function Parameter

What does an asterisk in front of a function parameter mean?
2. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
if remember correctly: * = a list, ** = a dictionary

Code:
```>>> def lis(*s):
print s

>>> lis(2,3,4,5,6,7,8,9)
(2, 3, 4, 5, 6, 7, 8, 9)
>>>
>>> def dic(**d):
print d

>>> dic(a=1)
{'a': 1}```
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2004
Location
Atlantic City, NJ
Posts
327
Rep Power
17
* is a tuple and ** is a dictionary.
4. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
Oh ya sorry it is a tuple :P

I never use it no wonder

5. Thanks, couldn't find any reference in the help file.
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2004
Posts
461
Rep Power
28
what is it used for? you can pass a tuple or a dictionary without defining that oyu are wanting one?
7. No Profile Picture
Contributing User
Devshed Intermediate (1500 - 1999 posts)

Join Date
Feb 2004
Location
London, England
Posts
1,585
Rep Power
1377
You use it when you want a program to be able to take any number of parameters, either positional (using *) or keywords (using **).

Here is an example using positional parameters. The function 'average' returns the average of all the parameters.
Code:
```>>> def average(*params):
...     return sum(params)/ float(len(params))
...
>>> average(1,2,3,4,25)
7.0
>>> average(1,2,3,4,25,100)
22.5```
You can also use * and ** when calling functions. This converts a sequence (*) or dictionary (**) into positional and keyword parameters respectively.
e.g.
Code:
```>>> x = [1,2,3,4,25,100]
>>> average( *x )
22.5```
Dave - The Developers' Coach