Python pow() Function Explained
By Rohit Sharma
Updated on Jun 14, 2023 | 4 min read | 6.1k views
Share:
For working professionals
For fresh graduates
More
By Rohit Sharma
Updated on Jun 14, 2023 | 4 min read | 6.1k views
Share:
Table of Contents
Python is one of the most significant and widely known programming languages in the modern era of technology. The Python interpreter has a wide spectrum of various built-in functions that are specifically built to perform particular tasks. This accounts for the versatility and flexibility of the programming language. One such built-in function supported by the Python interpreter is the Python power function. It is represented in general as pow(). Let us discuss more about the syntax, parameters and the return value of the Python power function in the subsequent sections.
Check out our other data science courses at upGrad.
The Python power function can be used when the user has a requirement of calculating the power of the inputs within a complex Python code. It can also be used in simpler calculations where the value of a number ‘x’ raised to the power ‘y’ is calculated. The power function in Python also allows the use of three inputs, say x, y and z. In such cases, the value returned by the function is equal to the ‘z’ modulus of ‘x’ raised to the power ‘y’. The general syntax of the Power function in Python is as mentioned below.
pow(x, y[, z])
The syntax will be pow(x,y) when only two input parameters are used.
Now that the basics of the power function in Python are thoroughly discussed let us look into the details of the parameters used in the Power function. The Python power function permits a maximum of three input parameters.
Input parameter ‘x’ |
Input Parameter ‘y’ |
Input Parameter ‘z’ |
Return Value |
Positive integer | Positive integer | Not assigned | Integer |
Positive integer | Positive integer | Not assigned | Floating point number |
Negative integer | Positive integer | Not assigned | Integer |
Negative integer | Negative integer | Not assigned | Integer |
Positive / negative integer | Positive / negative integer | Positive / negative integer | Integer |
The value of a number raised to a particular power can be determined using the Python pow() function. For example,
In Python, the power function can be used to determine the power of a variable ‘a’ over a variable ‘b’. When a third variable, ‘c’, is added to the equation, the pow() method returns ‘a’ to the power of ‘b’ , modulus of ‘c’.
print(pow(2,3)) # prints (2**3)
print(pow(3, 3, 10)) # prints (3**3)%10
Output:
8
7
There are several limitations to the built-in Python power function when utilizing the third argument (modulus), even though the base and exponents of the function can be negative, floating point numbers, or even complex numbers. They are:
You can learn both theoretical and practical aspects of Python with upGrad’s Professional Certificate in Data Science and Business Analytics from the University of Maryland. This course helps you learn Python from scratch. Even if you are new to programming and coding, upGrad will offer you a two-week preparatory course so that you can pick up on the basics of programming. you will learn about various tools like Python, SQL,, while working on multiple industry projects.
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources