gcd() in Python Last Updated : 14 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report gcd() function in Python is used to compute the Greatest Common Divisor (GCD) of two integers. It is available in the math module and returns the largest positive integer that divides both numbers without leaving a remainder. Example: Python import math a = 60 b = 48 print(math.gcd(a, b)) Output12 Explanation: The common divisors of 60 and 48 are [1, 2, 3, 4, 6, 12] and the greatest one is 12.Syntax of math.gcd()import mathmath.gcd(x, y)Parameters: x, y is Two non-negative integers (at least one of them must be non-zero).Returns:The greatest common divisor of x and y.If either x or y is 0, the result is the absolute value of the non-zero number.Examples of using math.gcd() functionExample 1: GCD of a number and 0 Python import math print(math.gcd(0, 25)) Output25 Explanation: When one number is 0, the gcd() returns the absolute value of the other number.Example 2: GCD of two co-prime numbers Python import math print(math.gcd(17, 29)) Output1 Explanation: 17 and 29 are co-prime (no common divisors except 1), so gcd() returns 1.Example 3: GCD in a list of numbers using functools.reduce() Python import math from functools import reduce nums = [48, 64, 80] # Find GCD of the list res = reduce(math.gcd, nums) print(res) Output16 Explanation: This finds the GCD of multiple numbers by applying math.gcd() cumulatively to the list elements. Comment More infoAdvertise with us Next Article gcd() in Python M manjeet_04 Follow Improve Article Tags : Python Practice Tags : python Similar Reads exec() in Python exec() function is used for the dynamic execution of Python programs which can either be a string or object code. If it is a string, the string is parsed as a suite of Python statements which is then executed unless a syntax error occurs and if it is an object code, it is simply executed. We must be 4 min read eval in Python Python eval() function parse the expression argument and evaluate it as a Python expression and runs Python expression (code) within the program.Python eval() Function SyntaxSyntax: eval(expression, globals=None, locals=None)Parameters:expression: String is parsed and evaluated as a Python expressio 5 min read float() in Python Python float() function is used to return a floating-point number from a number or a string representation of a numeric value. Example: Here is a simple example of the Python float() function which takes an integer as the parameter and returns its float value. Python3 # convert integer value to floa 3 min read Python Functions Python Functions is a block of statements that does a specific task. The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over an 9 min read Python int() Function The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part.Example:In this example, we passed a string as an argument to the int() function and printed it.Pythonage = "21" print("age =", int(age) 3 min read Like