Python: setting two variable values separated by a comma in python -
what difference in python between doing:
a, b = c, max(a, b)
and
a = c b = max(a, b)
what having 2 variable assignments set on same line do?
your 2 snippets different things: try a
, b
, c
equal 7
, 8
, 9
respectively.
the first snippet sets 3 variables 9
, 8
, 9
. in other words, max(a, b)
calculated before a
assigned value of c
. essentially, a, b = c, max(a, b)
push 2 values onto stack; variables a
, b
assigned these values when popped off.
on other hand, running second snippet sets 3 variables 9
. because a
set point value of c
before function call max(a, b)
made.
Comments
Post a Comment