In this tutorial, you will learn about the Python pow() method with the help of examples. Show
The Example
pow() SyntaxThe syntax of
pow() ParametersThe
pow() Return ValueThe
Example 1: Python pow()
Output 4 4 0.25 0.25 The In the above example,
Example 2: pow() with Modulus
Output 4 In the above example, we have raised the number 7 to the power 2 which results in 49. Since we have used the That's why we get the output 4. Recommended Readings:
The pow() function computes the power of a number. The pow() function takes two arguments (base value and power value) and, returns the power raised to the base number. For example, [Mathematics] xy = pow(x, y) [In programming] The C pow() Prototypedouble pow(double x, double y) The first argument is a base value and second argument is a power raised to the base value. To find the power of int or a float variable, you can explicitly convert the type to double using cast operator. int base = 3; int power = 5; pow(double(base), double(power)); Example: C pow() function
Output Enter the base number: 2.5 Enter the power raised: 3.4 2.5^3.4 = 22.54 ❮ Built-in Functions ExampleReturn the value of 4 to the power of 3 (same as 4 * 4 * 4): x = pow(4, 3) Try it Yourself » Definition and UsageThe If a third parameter is present, it returns x to the power of y, modulus z. SyntaxParameter Values
More ExamplesExampleReturn the value of 4 to the power of 3, modulus 5 (same as (4 * 4 * 4) % 5): x = pow(4, 3, 5) Try it Yourself » ❮ Built-in Functions DescriptionThe C library function double pow(double x, double y) returns x raised to the power of y i.e. xy. DeclarationFollowing is the declaration for pow() function. double pow(double x, double y) Parameters
Return ValueThis function returns the result of raising x to the power y. ExampleThe following example shows the usage of pow() function. #include <stdio.h> #include <math.h> int main () { printf("Value 8.0 ^ 3 = %lf\n", pow(8.0, 3)); printf("Value 3.05 ^ 1.98 = %lf", pow(3.05, 1.98)); return(0); } Let us compile and run the above program that will produce the following result − Value 8.0 ^ 3 = 512.000000 Value 3.05 ^ 1.98 = 9.097324 math_h.htm Which library has pow () function?C library function - pow()
The C library function double pow(double x, double y) returns x raised to the power of y i.e. xy.
What is pow () in Python?Python pow() Function
The pow() function returns the value of x to the power of y (xy). If a third parameter is present, it returns x to the power of y, modulus z.
Is POW a built in function in Python?Power Python: pow() Method. Python includes a built-in function that can be used to calculate powers: pow() . pow() accepts three parameters: a base number, an exponent to which the base is raised, and a modulo operator.
How do you find the POW in Python?How to find the power of a number in Python. import math. print(math. pow(4,2)) Run. Importing math module in Python.. def power(n,e): res=0. for i in range(e): res *= n. return res. print(pow(4,2)) Run. ... . def power(n, e): if e == 0: return 1. elif e == 1: return n. else: return (n*power(n, e-1)). |