Contents
Python math.lcm()
math.lcm(*integers) function returns the Least Common Multiple (LCM) of the integers passed as arguments.
Syntax
The syntax to call lcm() function is
math.lcm(*integers)
where
Parameter | Required | Description |
---|---|---|
*integers | No | None, one or multiple integer values. |
If no integer value is passed as argument to lcm(), then the return value is 1.
If only one integer is passed to lcm(), then then same value is returned as LCM.
If any non-integral value is passed as argument to lcm(), then the function raises TypeError.
Examples
LCM of two integers: 10 and 25.
Python Program
import math
result = math.lcm(10, 25)
print('lcm() :', result)
Run Output
lcm() : 50
LCM of one integer value.
Python Program
import math
result = math.lcm(5)
print('lcm() :', result)
Run Output
lcm() : 5
LCM of arguments containing floating point values.
Python Program
import math
result = math.lcm(5.5)
print('lcm() :', result)
Run Output
TypeError: 'float' object cannot be interpreted as an integer
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.lcm() function.