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 toxypow(x, y, z)is equal toxy % 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:
Deep Learning with Python - Francois Chollet
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Access Index of a List Using for Loop
Python if...else Statement
Python String casefold()
Python Program to Count the Number of Occurrence of a Character in String
Python round()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Merge Two Dictionaries
Python Program to Convert Kilometers to Miles
Python Type Conversion and Type Casting
Python issubclass()
Python Program to Print the Fibonacci sequence
Python Program to Convert Celsius To Fahrenheit
Python String isupper()
Python Program to Display the multiplication Table
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python bytearray()
Python iter()
Python Program to Find Armstrong Number in an Interval
Python Program to Copy a File
Python String upper()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python String maketrans()
Python Tuple index()
Python int()
Python datetime
Python String isprintable()
Python String islower()
Python Program to Check if a Number is Positive, Negative or 0
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python sorted()