[Python-Dev] Half-baked proposal: * (and **?) in assignments (original) (raw)

Patrick K. O'Brien pobrien@orbtech.com
Sat, 23 Nov 2002 12:29:47 -0600


On Friday 22 November 2002 08:34 pm, Gareth McCaughan wrote:

Since

def f(a,b,*c): ... f(1,2,3,4,5) does (in effect) a=1, b=2, c=(3,4,5), I suggest that a,b,*c = 1,2,3,4,5 should do a=1, b=2, c=(3,4,5) too.

Funny you should bring this up. Last Sunday I was demonstrating Python to some novice programmers and we were talking about tuple unpacking. Someone asked how you could unpack only the first couple of items from a tuple. I immediately decided to try the code that you suggested and was disappointed it didn't work (Not that I really expected it to work, but sometimes you surprise yourself.) Anyway, we then moved on to slicing, but I do like this approach that you suggest.

-- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien

"Your source for Python programming expertise."