[Tutor] REPL format

Alan Gauld alan.gauld at btinternet.com
Sun Apr 26 13:57:57 CEST 2015


On 26/04/15 02:28, Jim Mooney wrote:

> Another question - why does the first assignment work but not the second. I
> can see it's a syntax error but if Py can unpack in the first case why
> can't it unpack the same thing in the second?

I'm not sure what you expect it to unpack. Its already a variable 
pointing at a tuple without the *. What do you expect the * to do?

>>>> a, *b = 'ham', 'eggs', 'spam'
>>>> a
> 'ham'
>>>> b
> ['eggs', 'spam']
>>>> *b = 'eggs', 'spam'
> SyntaxError: starred assignment target must be in a list or tuple

 >>> b = 'eggs', 'spam'
 >>> b
('eggs', 'spam')



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list