Python Pow() (With Examples) - Programiz

Tutorials Courses Python JavaScript TypeScript SQL HTML CSS C C++ Java R Ruby RUST Golang Kotlin Swift C# DSA

Become a certified Python programmer.

ENROLL

Popular Tutorials

Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning Python

Popular Examples

Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year Explore Python Examples

Reference Materials

Built-in Functions List Methods Dictionary Methods String Methods View all Programiz Pro Logo

Created with over a decade of experience.

  • Learn
  • Practice
  • Compete
Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA Learn C Learn C++ Learn Java View all Courses on Programiz Pro Logo Python Basics Python Intermediate C++ Basics C++ Intermediate C++ OOP C Programming Java Basics Java Intermediate Java OOP View all Courses on Programiz Pro Logo Python Challenges JavaScript Challenges Java Challenges C++ Challenges C Challenges View all Challenges on Programiz Pro Logo Learn Practice Compete

Certification Courses

Created with over a decade of experience and thousands of feedback.

Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA View all Courses on Programiz Pro Logo Learn C Learn C++ Learn Java Python JavaScript TypeScript SQL HTML CSS C C++ Java More languages

Become a certified Python programmer.

Try Programiz PRO!

Popular Tutorials

Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning Python All Python Tutorials

Reference Materials

Built-in Functions List Methods Dictionary Methods String Methods View all Python JavaScript C C++ Java R Kotlin

Become a certified Python programmer.

Try Programiz PRO!

Popular Examples

Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year All Python Examples

Built-in Functions

  • Python abs()
  • Python any()
  • Python all()
  • Python ascii()
  • Python bin()
  • Python bool()
  • Python bytearray()
  • Python callable()
  • Python bytes()
  • Python chr()
  • Python compile()
  • Python classmethod()
  • Python complex()
  • Python delattr()
  • Python dict()
  • Python dir()
  • Python divmod()
  • Python enumerate()
  • Python staticmethod()
  • Python filter()
  • Python eval()
  • Python float()
  • Python format()
  • Python frozenset()
  • Python getattr()
  • Python globals()
  • Python exec()
  • Python hasattr()
  • Python help()
  • Python hex()
  • Python hash()
  • Python input()
  • Python id()
  • Python isinstance()
  • Python int()
  • Python issubclass()
  • Python iter()
  • Python list() Function
  • Python locals()
  • Python len()
  • Python max()
  • Python min()
  • Python map()
  • Python next()
  • Python memoryview()
  • Python object()
  • Python oct()
  • Python ord()
  • Python open()
  • Python pow()
  • Python print()
  • Python property()
  • Python range()
  • Python repr()
  • Python reversed()
  • Python round()
  • Python set()
  • Python setattr()
  • Python slice()
  • Python sorted()
  • Python str()
  • Python sum()
  • Python tuple() Function
  • Python type()
  • Python vars()
  • Python zip()
  • Python __import__()
  • Python super()

Python Tutorials

  • Python Operators
  • Python divmod()
  • Python Functions
  • Python Mathematical Functions
  • Python Iterators
  • Python Programming Built-in Functions
Python pow()

The pow() method computes the power of a number by raising the first argument to the second argument

Example

# compute 3^4 print(pow(3, 4)); # Output: 81

pow() Syntax

The syntax of pow() is:

pow(number, power, modulus [optional])

pow() Parameters

The pow() method takes three parameters:

  • number- the base value that is raised to a certain power
  • power - the exponent value that raises number
  • modulus - (optional) divides the result of number paused to a power and finds the remainder: number^power% modulus

pow() Return Value

The pow() method returns:

  • number^power - number, raised to a certain power
  • number^power % modulus - with the modulus argument
  • 1 - if the value of power is 0
  • 0 - if the value of number is 0

Example 1: Python pow()

# returns 2^2 print(pow(2, 2)) # returns -2^2 print(pow(-2, 2)) # returns 1/2^2 print(pow(2, -2)) # returns -1/-2^2 print(pow(-2, -2))

Output

4 4 0.25 0.25

The pow() method helps us find the value of a number raised to a certain power.

In the above example,

  • pow(2,2) is 22 - results in 4
  • pow(-2,2) is -22 - results in -4
  • pow(2,-2) is 1/22 - results in 0.25
  • pow(-2,-2) is -1/-22 - results in 0.25

Example 2: pow() with Modulus

x = 7 y = 2 z = 5 # compute x^y % z print(pow(x, y, z))

Output

4

In the above example, we have raised the number 7 to the power 2 which results in 49.

Since we have used the pow() method with three arguments x, y, and z, the third argument 5 divides the result of 72 and finds the remainder.

That's why we get the output 4.

Also Read:

  • Python id()
  • Python int()
  • Python Program to Compute the Power of a Number
Previous Tutorial: Python open() Next Tutorial: Python print() Share on: Did you find this article helpful?

Sorry about that.

How can we improve it? Feedback * Leave this field blank

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community

Python References

Python Library

Python print()

Python Library

Python divmod()

Python Library

Python eval()

Python Library

Python max()

Từ khóa » Hàm Pow Trong Python