This is in the standard library .
>>> from fractions import gcd >>> gcd(20,8) 4
Source code from inspect module in Python 2.7:
>>> print inspect.getsource(gcd) def gcd(a, b): """Calculate the Greatest Common Divisor of a and b. Unless b==0, the result will have the same sign as b (so that when b is divided by it, the result comes out positive). """ while b: a, b = b, a%b return a
Starting with Python 3.5, gcd is in the math module ; one in fractions deprecated. Moreover, inspect.getsource no longer returns explanatory source code for both methods.
user545424 Jun 24 '12 at 5:19 2012-06-24 05:19
source share