Syntactic sugar for assignment statements: one value to multiple targets?

Chris Angelico rosuav at gmail.com
Wed Aug 17 05:45:24 EDT 2011


On Wed, Aug 17, 2011 at 10:26 AM, gc <gc1223 at gmail.com> wrote:
> On Aug 17, 3:13 am, Chris Angelico <ros... at gmail.com> wrote:
>
>> Minor clarification: You don't want to initialize them to the same
>> value, which you can do already:
>>
>> a=b=c=d=e=dict()
>
> Right. Call the proposed syntax the "instantiate separately for each
> target" operator.  (It can be precisely defined as a * on the RHS of a
> one-into-many assignment statement--i.e. an assignment statement with
> 1 object on the RHS and more than 1 on the LHS).
>

Agreed, but there's no requirement for it to be instantiating
something (although that will be common). "dict()" is an expression
that you want to evaluate five (or however many) times. It might just
as easily be some other function call; for instance:

head1,head2,head3=file.readline()

to read three lines from a file. Or it mightn't even be a function call per se.

ChrisA



More information about the Python-list mailing list