Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconSoftware Developmentbreadcumb forward arrow iconPython pow() Function Explained

Python pow() Function Explained

Last updated:
13th Jun, 2023
Read Time
4 Mins
share image icon
In this article
Chevron in toc
View All
Python pow() Function Explained

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. 

Introduction to the Python Power function:

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])

Ads of upGrad blog

The syntax will be pow(x,y) when only two input parameters are used.

Explore our Popular Data Science Courses

Python Power function parameters:

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.

  • The parameter ‘x’: It is a compulsory variable and represents the number whose power is to be determined.
  • The parameter ‘y’: It is also an obligatory input parameter. It represents the number to which the parameter ‘x’ should be powered. 
  • The parameter ‘z’: It is an optional input parameter. This parameter derives the modulus of the power value obtained when ‘x’ is raised to the power ‘y’.

Read our popular Data Science Articles

Power Method in Python: Different cases of input parameters:

  • The argument ‘x’ can be either a positive integer or a negative integer. It is mandatory for the programmer to assign a value to this parameter.
  • The parameter ‘y’ also is a compulsory input parameter and accept the value that is either positive or negative integers.
  • The parameter ‘z’ is optional. It may or may not be passed as per the user’s requirement. If assigned a value, the parameter ‘z’ can take up any positive or negative integer.

Return values of Python Power Function:

Input parameter ‘x’

Input Parameter ‘y’

Input Parameter ‘z’ 

Return Value

Positive integerPositive integer Not assignedInteger
Positive integerPositive integerNot assignedFloating point number
Negative integerPositive integerNot assigned Integer
Negative integerNegative integerNot assignedInteger
Positive / negative integerPositive / negative integerPositive / negative integerInteger

Understanding Python Power Function with Examples

The value of a number raised to a particular power can be determined using the Python pow() function. For example,

  • pow(3,3) is 33– results in 27
  • pow(-3,3) is -33 – results in -27
  • pow(3,-3) is 1/ 33 – results in 0.037
  • pow(-3,-3) is -1/-33 – results in – 0.037

When To Use pow() In Python?

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’.

Complexity of Python pow()

  • Time Complexity: O(1)
  • Auxiliary Space: O(1)

Code Example

print(pow(2,3)) # prints (2**3)

print(pow(3, 3, 10)) # prints (3**3)%10



Ads of upGrad blog


Exceptions Of pow() In Python

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:

  • We receive a “ValueError” stating that a complex number cannot be used with a modulus when we supply a complex number as the basis and utilize the third argument (modulus).
  • We receive a “TypeError” that specifies that floating-point parameters cannot be used with a modulus since we can only use a modulus with integers when we supply a floating-point number as the base when using the third argument (modulus).
  • We receive a “ValueError” that specifies that a negative exponent cannot be used with a modulus when we pass a negative value as the exponent while utilizing the third argument (modulus). Since we already know that we cannot use a modulus with a floating point number, the problem is caused by the fact that a negative exponent produces a result that is a floating point number between 0 and 1.
  • In pow() Python math, we receive a “ValueError” message when we attempt to utilize a negative base with a floating point exponent by passing a negative base and a floating point exponent to math.pow().

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.


Rohit Sharma

Blog Author
Rohit Sharma is the Program Director for the UpGrad-IIIT Bangalore, PG Diploma Data Analytics Program.

Explore Free Courses

Suggested Blogs

35 Must Know Agile Methodology Interview Questions & Answers: Ultimate Guide 2023
Attending an agile interview and wondering what are all the questions and discussions you will go through? Before attending an agile testing interview
Read More

by Arjun Mathur

20 Nov 2023

DevOps Engineer Salary in India in 2023 [For Freshers & Experienced]
Wondering what is the range of DevOps Salary in India? In the last few years, DevOps has evolved from being just a “buzzword” to a mainstream practic
Read More

by upGrad

07 Nov 2023

What Is AWS Route 53 and How Does It Work?
Managing domain names and directing traffic efficiently is pivotal in the intricate web of cloud computing and web hosting. Enter AWS Route 53, Amazon
Read More

by Pavan Vadapalli

29 Sep 2023

Agile vs Scrum: Difference Between Agile and Scrum
Keeping up with the fast-paced nature of project development fueled by technological progress is challenging, to say the least. To function efficientl
Read More

by Pavan Vadapalli

28 Sep 2023

What Is Azure Active Directory? A Complete Guide
In the ever-evolving landscape of cloud computing, Azure Active Directory or Azure AD has emerged as a cornerstone in identity and access management.
Read More

by Pavan Vadapalli

28 Sep 2023

Difference Between Product Backlog and Sprint Backlog: A Quick Guide
Agile is a highly effective project management methodology, but its efficiency relies on the team’s collective understanding of key concepts, su
Read More

by Pavan Vadapalli

28 Sep 2023

Agile Manifesto Explained: Understanding Agile Values
Manifestos are formal declarations of principles or beliefs that guide movements or ideologies. The impact of the Agile Manifesto principles has exten
Read More

by Pavan Vadapalli

28 Sep 2023

Top 22 Best Agile Project Management Tools in 2023
The recent years have seen a surge in using the best Agile management tools and techniques, especially in software development. Breaking down projects
Read More

by Pavan Vadapalli

27 Sep 2023

Scrum Master Roles and Responsibilities: Everything You Should Know
In today’s fast-paced business environment, organisations constantly seek ways to enhance their productivity, collaboration, and product quality
Read More

by Pavan Vadapalli

27 Sep 2023

Schedule 1:1 free counsellingTalk to Career Expert
footer sticky close icon