What does *x mean?

Emile van Sebille emile at fenx.com
Thu Nov 8 15:15:21 EST 2001


"Erann Gat" <gat at jpl.nasa.gov> wrote in message
news:gat-0811011133410001 at jansma-mac.jpl.nasa.gov...
> I've heard people mention "the new *x syntax".  Does Python have a prefix
> * operator now?  What does it do?  (It's not mentioned in the online
> language reference at python.org.)  Email replies preferred.  Thanks!
>
> Erann gat
> gat at jpl.nasa.gov

These are references to the ability to pass on function arguments to other
functions.

For example:

ActivePython 2.1, build 210 ActiveState)
based on Python 2.1 (#15, Apr 19 2001, 10:28:27) [MSC 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def showargs(*args, **kwargs):
...     print "args: %s\nkwargs:%s" % (args, kwargs)
...
>>> def passargs(*args, **kwargs):
...     showargs(*args, **kwargs)
...
>>> passargs(1,2,3,a=5,b=6,c=7)
args: (1, 2, 3)
kwargs:{'b': 6, 'c': 7, 'a': 5}
>>>


HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list