zip() or what?
Erik Max Francis
max at alcyone.com
Thu Jul 3 13:55:06 EDT 2003
More information about the Python-list mailing list
Thu Jul 3 13:55:06 EDT 2003
- Previous message (by thread): zip() or what?
- Next message (by thread): zip() or what?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ray Tomes wrote: > I can understand the 2nd one, but I don't get the meaning of the * in > the > first. Is this like the opposite of putting [] around something or > what? > Under what circumstances can an * be used like this, and what is it > called? - I don't know how to look for it in the docs :-) f(x) calls the function f with the single argument x. f(*x) calls f with the arguments x, which is expected to be a sequence. The * syntax comes from defining functions, where a formal argument preceded by * means, "All the rest of the arguments as a tuple." So: >>> def f(*x): print x ... >>> s = [1, 2, 3] >>> f(s) ([1, 2, 3],) >>> f(*s) (1, 2, 3) The old way of writing the function call f(*x) was apply(f, x). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ War is like love, it always finds a way. \__/ Bertolt Brecht
- Previous message (by thread): zip() or what?
- Next message (by thread): zip() or what?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list