[Tutor] timed functions? Timeouts?
Moishy Gluck
moishyyehuda at gmail.com
Tue May 20 23:33:38 CEST 2008
#A single " * " accepts arbitrary amount of unnamed parameters. Two " ** "
accepts an arbitrary amount of unnamed parameters.
# Using asterisk.
def FuncOne(*list, **dict):
for color in list:
print color
print ""
for [color, value] in dict.items():
print color.ljust(5), ":", value
# Not using asterisk.
def FuncTwo(list, dict):
for color in list:
print color
print ""
for [color, value] in dict.items():
print color.ljust(5), ":", value
#A single " * " turns a list into unnamed parameters. Two " ** " dictionary
in named parameters.
colors = ["red", "green", "blue"]
rgbValues = {"red": "ff0000", "green": "00ff00", "blue": "0000ff", }
print "FuncOne:\n"
# Using asterisk.
FuncOne(*colors, **rgbValues)
print "\n\nFuncTwo:\n"
# Not using asterisk.
FuncTwo(colors, rgbValues)
---------------
outputs to:
FuncOne:
red
green
blue
blue : 0000ff
green : 00ff00
red : ff0000
FuncTwo:
red
green
blue
blue : 0000ff
green : 00ff00
red : ff0000
On Tue, May 20, 2008 at 2:12 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:
>
> "Kent Johnson" <kent37 at tds.net> wrote
>
> Then I'm a little confused by the * and ** - they look just like the
>>> pointer and pointer to a pointer in C++, but do they perform the same
>>> function in python?
>>>
>>
>> No, these are not pointers, they allow passing arbitrary lists and
>> dicts of arguments. I don't know of a good writeup of this syntax;
>>
>
> Soince you (the OP) seem to know some C the */** parameters
> are somewhat similar to varargs in C. (as used in functions like
> printf)
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080520/50add8a4/attachment.htm>
More information about the Tutor
mailing list