Talk:Euclidean algorithm (Python)

From LiteratePrograms
Jump to: navigation, search

Nice article - how can I understand the body of the while loop - namely:

a, b = b%a, a

What is that construct called? I would like to figure that out.

Thank you

--Mbubb (talk) 20:24, 30 May 2014 (UTC)


This is multiple assignment. var a becomes b%a ; then b adopts the stale value of a. The C implementation of gcd() uses a temporary value to swap the values in an order that doesn't overwrite either one prematurely. Python's runtime handles that here for us.

Also, this explanation is so stilted I barely believe it isn't from an unattributed textbook. --Nzen :: 1 June 14