def gcd(x, y):
while(y): x, y = y, x % y
return x
The function above returns the greatest common divisor of two numbers. Why is y used as the condition in the while loop?
This is used because the x % y will reduce y to the remainder of x / y (also called modulo) with each iteration of the loop. So the loop will execute as long as y 'is true' or in other words as long as y has a value that is not None or zero.
None, but not "null". If we're being picky, there are a whole set of things that are "false-ish", all of which work as Booleans.None) but it's a little misleading since there's no way y could be None.print(None == 0).