assignment in control structure syntax (was Re: Curious assignment behaviour)
Paul Rubin
phr-n2001d at nightsong.com
Thu Oct 11 04:11:44 EDT 2001
Chris Dutton <chris at cmb-enterprises.com> writes:
> > 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)
Hey, I like that, especially if you can use that PROG-like structure
in ordinary expressions, similar to the comma operator in C.
> The example I saw somewhere that I liked was
>
> if something as x:
> do_something_to(x)
That's ok too, as long as the comparison doesn't have to be with zero:
if (something as x) == 3:
do_something_to(x)
More information about the Python-list
mailing list