a = b = 1 just syntactic sugar?

Fredrik Lundh fredrik at pythonware.com
Tue Jun 3 18:23:03 EDT 2003


Ed Avis wrote:

> Is there a way to write an expression which sets b and does return
> something?

an inline assignment can be written as:

    [b for b in [expr]]

to return the assigned value, use:

    [b for b in [expr]][0]

for example:

>>> a = 10
>>> c = [b for b in [a+a]][0] + a
>>> a
10
>>> b
20
>>> c
30

</F>








More information about the Python-list mailing list