Return value of an assignment statement?

George Sakkis george.sakkis at gmail.com
Fri Feb 22 23:00:43 EST 2008


On Feb 22, 1:16 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:

> On Fri, 22 Feb 2008 08:19:07 -0800, Carl Banks wrote:
> > (The perl example wasn't using an assignment operator.)
>
> Hmmm... I see. Obviously I didn't pretend to understand Perl well enough.
>
> (I assume you're ignoring the assignments $name = chop(\1) etc. Fair
> enough.)
>
> [...]
>
> > I can't help but to think that a lot of people's distaste for this
> > natural way to write certain logic is simply defensiveness about one
> > minor little thing that Python doesn't support (without workarounds).
>
> But Python certainly does support set-and-test. You just have
> to separate the set from the test with a newline:

A single "set-and-test" operation is not equivalent to two consecutive
operations, "set" and "test".

> m = re.match(r"name=(.*)",line)  # set
> if m:  # test
>     name = m.group(1).strip()

For a single set-and-test the inconvenience is minimal, but stack a
bunch of them together (even more if there are 'else' clauses in the
mix) and the syntactic inefficiency becomes quite visible.

George



More information about the Python-list mailing list