[Tutor] Understanding code line

Ben Finney ben+python at benfinney.id.au
Fri Mar 21 23:34:15 CET 2014


Gary <gwengstrom at yahoo.com> writes:

> Pythonists
>
> I am trying to understand the difference between
>
> a = b

Retrieves the value referenced by ‘b’, then binds the name ‘a’ to the
value.

> b = a + b

Evaluates the expression ‘a + b’, then binds the name ‘b’ to the result.

>  and
>
> a,b = b, a+ b

Evaluates the expression ‘b, a + b’ – which will be a two-value tuple –
then binds the names ‘a’ and ‘b’ to the two values from that tuple.

Since the right side of the assignment, in each case, is evaluated
before bindling the left side, the resulting values will depend on what
the names are *currently* bound to at the time of evaluation.

-- 
 \        “When in doubt tell the truth. It will confound your enemies |
  `\   and astound your friends.” —Mark Twain, _Following the Equator_ |
_o__)                                                                  |
Ben Finney



More information about the Tutor mailing list