Python: setting two variable values separated by a comma in python

Your two snippets do different things: try with a, b and c equal to 7, 8 and 9 respectively.

The first snippet sets the three variables to 9, 8 and 9. In other words, max(a, b) is calculated before a is assigned to the value of c. Essentially, all that a, b = c, max(a, b) does is push two values onto the stack; the variables a and b are then assigned to these values when they are popped back off.

On the other hand, running the second snippet sets all three variables to 9. This is because a is set to point to the value of c before the function call max(a, b) is made.

Leave a Comment