assignment in control structure syntax (was Re: Curious assignment behaviour)

Dale Strickland-Clark dale at
Thu Oct 11 11:55:41 CEST 2001

Chris Dutton <chris at> wrote:

>in article slrn9s9h7p.1jk.huaiyu at, Huaiyu Zhu at
>huaiyu at wrote on 10/10/01 6:00 PM:
>> There are several other uses for this syntax.  For example,
>> if val = dict1[key1]; val:
>> process1(val)
>> elif val = dict2[key2]; val:
>> process2(val)
>> elif mylist += otherlist; len(mylist) > 4:
>> process3(mylist)
>The example I saw somewhere that I liked was
>if something as x:
>   do_something_to(x)

Presumably, 'something as x' assigns to x and yields x?

It doesn't seem at all obvious to me. I had to think about it for a
while before figuring it out. Also, having an assignment working to
the right is very counter-intuitive.
Dale Strickland-Clark
Riverhall Systems Ltd

More information about the Python-list mailing list