In Python, math module contains a number of mathematical operations, which can be performed with ease using the module.
math.gcd() function compute the greatest common divisor of 2 numbers mentioned in its arguments.
Syntax: math.gcd(x, y)
x : Non-negative integer whose gcd has to be computed.
y : Non-negative integer whose gcd has to be computed.
Returns: An absolute/positive integer value after calculating the GCD of given parameters x and y.
Exceptions : When Both x and y are 0, function returns 0, If any number is a character, Type error is raised.
The gcd of 60 and 48 is : 12
math.gcd(44, 12) : 4 math.gcd(69, 23) : 5
Code #3: Explaining Exception.
The gcd of 0 and 0 is : 0 The gcd of a and 13 is : TypeError: 'str' object cannot be interpreted as an integer
- Python - Call function from another function
- Python | hex() function
- Python | now() function
- Python | How to get function name ?
- Python map() function
- Python | cmp() function
- Python tell() function
- Help function in Python
- Python | dir() function
- id() function in Python
- sum() function in Python
- ord() function in Python
- Python | int() function
- Python | oct() function
- Python | randint() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.