A small inconsistency in syntax?
BrianQ at ActiveState.com
Mon Oct 29 22:34:32 CET 2001
> Brian Quinlan wrote:
> >I could want to write:
> >a = ['x value','y value','z value'] = x
> >Here the intermediate list is doing 3 things for me:
> >1. it's providing documentation
> >2. it's forcing the sequence type to be of length 3
> >3. it's making the type assigned to 'a' a list
> 4. it's providing a handy way to generate a syntax error ;-)
> Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit
> (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> >>> a = ['x value','y value','z value'] = 1,2,3
> SyntaxError: can't assign to literal
That was exactly the point of the original argument - that it is
reasonable to do sequence unpacking into mutable literals even though
the language does not allow it.
More information about the Python-list