Python 3.9+mathterm
math.lcm
combinatorics
Returns the least common multiple of the integers. math.lcm(4, 6) → 12. Python 3.9+.
Syntax
math.lcm(*integers)
Zero is absorbing: if any argument is 0 the result is 0, so a single zero in a list silently wipes out the whole fold. With no arguments the answer is 1, which makes 1 the right seed when accumulating. The function only arrived in Python 3.9; on older versions you emulate it with the product divided by the gcd.
Examples
import math
print(math.lcm(4, 6)) # → 12
print(math.lcm(12, 18)) # → 36
print(math.lcm(3, 5, 7)) # → 105
print(math.lcm(0, 5)) # → 0
print(math.lcm(1, 100)) # → 100
print(math.lcm(6, 10, 15)) # → 30
See also
Open in the full glossarydocs.python.orgReport an inaccuracy