Table of Contents
The pow() function returns the power of a number.
The syntax of pow() is:
pow(x, y, z)
1. pow() Parameters
The pow() function takes three parameters:
- x – a number, the base
- y – a number, the exponent
- z (optional) – a number, used for modulus
Hence,
- pow(x, y)is equal to- xy
- pow(x, y, z)is equal to- xy % z
2. Example 1: Python pow()
# positive x, positive y (x**y) print(pow(2, 2)) # 4 # negative x, positive y print(pow(-2, 2)) # 4 # positive x, negative y print(pow(2, -2)) # 0.25 # negative x, negative y print(pow(-2, -2)) # 0.25
Output
4 4 0.25 0.25
3. Example 2: pow() with three arguments (x**y) % z
x = 7 y = 2 z = 5 print(pow(x, y, z)) # 4
Output
4
Here, 7 powered by 2 equals 49. Then, 49 modulus 5 equals 4.
Related posts:
Python Custom Exceptions
Python String casefold()
Python Program to Append to a File
Python String format()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Set intersection_update()
Python Program to Find the Factors of a Number
Python Set discard()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Add Two Matrices
Python String lstrip()
Python Set union()
Python Program to Print Colored Text to the Terminal
Python Dictionary pop()
Python any()
Python Anonymous / Lambda Function
Python round()
Python Program to Solve Quadratic Equation
Python String rjust()
Python Get Current time
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Get a Substring of a String
Python Program to Illustrate Different Set Operations
Python staticmethod()
Python Program to Check Whether a String is Palindrome or Not
Python Multiple Inheritance
Python if...else Statement
Python String splitlines()
Python Machine Learning - Sebastian Raschka
Python Program to Check if a Number is Odd or Even
Python bin()
 
