Python pow Function with Examples - Python Tutorial | Logic Practice
Python Course / Other / Python pow Function with Examples

Python pow Function with Examples

BLUF: This lesson on Python pow Function with Examples provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python pow Function with Examples

Mastering Python pow Function with Examples is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

In Python, the pow function serves the purpose of calculating the exponentiation of a number. When a third argument (z) is provided, it computes x raised to the power of y, followed by taking the modulus with z, expressed as (x, y) % z.

Python pow Function Syntax

It has the following syntax:

Example

pow(x, y, z)

Parameters

It has the following parameters:

  • x: It is a number, a base
  • y: It is a number, an exponent.
  • z (optional): It is a number and the modulus.
  • Return

It computes x raised to the power of y, and then takes the result modulo z, provided that a third parameter (z) is specified, which can be expressed as (x, y) % z.

Different Examples for Python pow Function

In this section, we will explore various instances of the Python pow function.

Python pow Function Example

The following example illustrates how the pow function operates in Python.

Example

# positive x, positive y (x**y)

print(pow(4, 2))

# negative x, positive y

print(pow(-4, 2))

# positive x, negative y (x**-y)

print(pow(4, -2))

# negative x, negative y

print(pow(-4, -2))

Output:

Output

16

16

0.0625

0.0625

Clarification: In the preceding example, we have utilized various values for the parameters (x, y), which computes x raised to the power of y.

Python pow Function Example

The following example demonstrates the usage of pow with three parameters (x, y, z)

Example

x = 4

y = 7

z = 3

print(pow(x, y, z))

Output:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience