Python standard library's math module provides functions to calculate gcd math.gcd and lcm math.lcm.
math
math.gcd
math.lcm