Python pow() Function – Tutorial with Examples

The pow() function in Python is a built-in function that is used to calculate the power of a number. It is used to raise a number to a specified power. The function is available in the math module, so it must be imported before it can be used.

Syntax

pow(x, y, z)

Parameters

  • x : The base number.
  • y : The exponent.
  • z (optional) : The modulo.

Return Value

The pow() function returns the result of x raised to the power of y, calculated modulo z if specified.

Examples

Example 1: Basic pow() usage

result = pow(2, 3)
print(result)

Output

8

In this example, the pow() function is used to calculate 2 raised to the power of 3. The result is 8, which is printed to the console using the print() function.

Example 2: Using the modulo parameter

result = pow(2, 3, 5)
print(result)

Output

3

In this example, the pow() function is used to calculate 2 raised to the power of 3, with a modulo of 5. The result is 3, which is printed to the console using the print() function.

Use Cases

The pow() function is useful for many mathematical calculations, including the calculation of exponents and roots. It is commonly used in scientific and engineering applications, as well as in cryptography and other fields where mathematical calculations are necessary. The function is fast and reliable, making it a good choice for many different types of applications.

Leave a Reply

Your email address will not be published. Required fields are marked *