-3

Found it here

Also, does it read right to left or vice versa?

Kreyul
  • 1
  • 1
    Please include any code relevant to your question in the question itself, not via links. But to answer the question, it's just a shorthand way to assign to both the `a` and `b` variables at once. It's like `a = b` then `b = a%b` but where the second assignment is using the *original* value of `a` rather than the new one. For example `a, b = b, a` lets you swap two variables over without requiring a temporary variable. – Robin Zigmond Mar 06 '19 at 08:32
  • 2
    Possible duplicate of [How does Python's comma operator works during assignment?](https://stackoverflow.com/questions/11502268/how-does-pythons-comma-operator-works-during-assignment) – Robin Zigmond Mar 06 '19 at 08:33
  • Possible duplicate of [Is there a standardized method to swap two variables in Python?](https://stackoverflow.com/questions/14836228/is-there-a-standardized-method-to-swap-two-variables-in-python) – Sanjeev S Mar 06 '19 at 08:33
  • 1
    Possible duplicate of [Multiple assignment and evaluation order in Python](https://stackoverflow.com/questions/8725673/multiple-assignment-and-evaluation-order-in-python) – Thierry Lathuille Mar 06 '19 at 08:40

1 Answers1

1

In assignment statements in python, the right-hand side is evaluated first before doing the actual setting of variables. So,

a , b = b, a%b

evaluates b (let's call the result temp1), evaluates a%b which is a mod b (call that temp2), then sets a to temp1 and b to temp2.

Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56