On this page
math.gcd
Prev: math.gamma | Up: math | Next: math.hypot
Rel: math.acos, math.acosh, math.asin, math.asinh
Ref: docs.python.org — math.gcd
Tags: #public #python3 #stdlib #math
Import
import math
from math import gcd
Signature & Overview
math.gcd(*integers)
Greatest Common Divisor.
Usage
import math
assert math.gcd(48, 18) == 6
assert math.gcd(12, 18, 30) == 6
Gotchas
- Accepts any number of integer arguments (Python 3.9+):
math.gcd()with no args returns0, and results are always non-negative.
REPL Inspect
from math import gcd
help(gcd)
Linked from
Related notes
- tuts/python3/stdlib_module/math/gamma Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/hypot Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/math/acos Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/acosh Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asin Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asinh Linked here; shared tags: #math, #stdlib
- tuts/c/stdlib/math shared tags: #math, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #math, #stdlib
- tuts/c/stdlib/math/floor shared tags: #math, #stdlib