Python pow() method

## TLDR <!– wp:list –> <ul class=”wp-block-list”><!– wp:list-item –> <li>pow(a, n) raises a to the power n – same as a ** n</li> <!– /wp:list-item –> <!– wp:list-item –> <li>pow(a, n, b) adds modular exponentiation: (a ** n) % b – faster for large numbers</li> <!– /wp:list-item –> <!– wp:list-item –> <li>The third argument requires a positive exponent – negative exponents with modulus raise a ValueError</li> <!– /wp:list-item –> <!– wp:list-item –> <li>pow() beats math.pow() for integers – no float conversion, supports modulus, and handles big integers natively</li> <!– /wp:list-item –> <!– wp:list-item –> <li>Both two-argument and three-argument forms accept any numeric type, including negative exponents and fractions</li> <!– /wp:list-item –> </ul> <!– /wp:list –> ## How pow() Works in Python ### Two-Argument Form

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

### Three-Argument Form (Modular Exponentiation)

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951


x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

### Supporting Both Forms in a Single Function

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

## pow() vs math.pow() – What’s the Difference?

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

### Performance Difference

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

## Practical Use Cases ### Modular Arithmetic in Cryptography

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

### Compound Interest Calculations

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

### Finding Large Powers Modulo a Number

x = pow(2, 5)      # 2 raised to the power 5
print(x)           # 32

y = pow(4, -2)     # 1 / (4 squared)
print(y)           # 0.0625

z = pow(2, 0.5)    # square root of 2
print(z)           # 1.4142135623730951

## FAQ </div> <div class=”ct-share-box is-width-constrained ct-hidden-sm” data-location=”bottom” data-type=”type-1″ > <div data-icons-type=”simple”> <a href=”https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fbuilt-in-methods%2Fpython-pow” data-network=”facebook” aria-label=”Facebook” rel=”noopener noreferrer nofollow”> <span class=”ct-icon-container”> <svg width=”20px” height=”20px” viewBox=”0 0 20 20″ aria-hidden=”true”> <path d=”M20,10.1c0-5.5-4.5-10-10-10S0,4.5,0,10.1c0,5,3.7,9.1,8.4,9.9v-7H5.9v-2.9h2.5V7.9C8.4,5.4,9.9,4,12.2,4c1.1,0,2.2,0.2,2.2,0.2v2.5h-1.3c-1.2,0-1.6,0.8-1.6,1.6v1.9h2.8L13.9,13h-2.3v7C16.3,19.2,20,15.1,20,10.1z”/> </svg> </span> </a> <a href=”https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fbuilt-in-methods%2Fpython-pow&text=Python%20pow()%20method” data-network=”twitter” aria-label=”X (Twitter)” rel=”noopener noreferrer nofollow”> <span class=”ct-icon-container”> <svg width=”20px” height=”20px” viewBox=”0 0 20 20″ aria-hidden=”true”> <path d=”M2.9 0C1.3 0 0 1.3 0 2.9v14.3C0 18.7 1.3 20 2.9 20h14.3c1.6 0 2.9-1.3 2.9-2.9V2.9C20 1.3 18.7 0 17.1 0H2.9zm13.2 3.8L11.5 9l5.5 7.2h-4.3l-3.3-4.4-3.8 4.4H3.4l5-5.7-5.3-6.7h4.4l3 4 3.5-4h2.1zM14.4 15 6.8 5H5.6l7.7 10h1.1z”/> </svg> </span> </a> <a href=”#” data-network=”pinterest” aria-label=”Pinterest” rel=”noopener noreferrer nofollow”> <span class=”ct-icon-container”> <svg width=”20px” height=”20px” viewBox=”0 0 20 20″ aria-hidden=”true”> <path d=”M10,0C4.5,0,0,4.5,0,10c0,4.1,2.5,7.6,6,9.2c0-0.7,0-1.5,0.2-2.3c0.2-0.8,1.3-5.4,1.3-5.4s-0.3-0.6-0.3-1.6c0-1.5,0.9-2.6,1.9-2.6c0.9,0,1.3,0.7,1.3,1.5c0,0.9-0.6,2.3-0.9,3.5c-0.3,1.1,0.5,1.9,1.6,1.9c1.9,0,3.2-2.4,3.2-5.3c0-2.2-1.5-3.8-4.2-3.8c-3,0-4.9,2.3-4.9,4.8c0,0.9,0.3,1.5,0.7,2C6,12,6.1,12.1,6,12.4c0,0.2-0.2,0.6-0.2,0.8c-0.1,0.3-0.3,0.3-0.5,0.3c-1.4-0.6-2-2.1-2-3.8c0-2.8,2.4-6.2,7.1-6.2c3.8,0,6.3,2.8,6.3,5.7c0,3.9-2.2,6.9-5.4,6.9c-1.1,0-2.1-0.6-2.4-1.2c0,0-0.6,2.3-0.7,2.7c-0.2,0.8-0.6,1.5-1,2.1C8.1,19.9,9,20,10,20c5.5,0,10-4.5,10-10C20,4.5,15.5,0,10,0z”/> </svg> </span> </a> <a href=”https://www.linkedin.com/shareArticle?url=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fbuilt-in-methods%2Fpython-pow&title=Python%20pow()%20method” data-network=”linkedin” aria-label=”LinkedIn” rel=”noopener noreferrer nofollow”> <span class=”ct-icon-container”> <svg width=”20px” height=”20px” viewBox=”0 0 20 20″ aria-hidden=”true”> <path d=”M18.6,0H1.4C0.6,0,0,0.6,0,1.4v17.1C0,19.4,0.6,20,1.4,20h17.1c0.8,0,1.4-0.6,1.4-1.4V1.4C20,0.6,19.4,0,18.6,0z M6,17.1h-3V7.6h3L6,17.1L6,17.1zM4.6,6.3c-1,0-1.7-0.8-1.7-1.7s0.8-1.7,1.7-1.7c0.9,0,1.7,0.8,1.7,1.7C6.3,5.5,5.5,6.3,4.6,6.3z M17.2,17.1h-3v-4.6c0-1.1,0-2.5-1.5-2.5c-1.5,0-1.8,1.2-1.8,2.5v4.7h-3V7.6h2.8v1.3h0c0.4-0.8,1.4-1.5,2.8-1.5c3,0,3.6,2,3.6,4.5V17.1z”/> </svg> </span> </a> </div> </div> <div class=”author-box is-width-constrained ct-hidden-sm” data-type=”type-2″ > <a href=”https://www.askpython.com/author/snehashish” class=”ct-media-container”><img decoding=”async” src=”https://secure.gravatar.com/avatar/68c5c7e79f00696a90307c85ff1d6ff1ccdf763878bc893ef1f04ab49f180256?s=120&d=mm&r=g” width=”60″ height=”60″ alt=”Sneh” style=”aspect-ratio: 1/1;”> <svg width=”18px” height=”13px” viewBox=”0 0 20 15″> <polygon points=”14.5,2 13.6,2.9 17.6,6.9 0,6.9 0,8.1 17.6,8.1 13.6,12.1 14.5,13 20,7.5 “/> </svg> </a> <section> <h5 class=”author-box-name”> Sneh </h5> <div class=”author-box-bio”> </div> <a href=”https://www.askpython.com/author/snehashish” class=”ct-author-box-more”>Articles: 36</a> </section> </div> <nav class=”post-navigation is-width-constrained ” > <a href=”https://www.askpython.com/python/examples/pythonic-way-of-coding” class=”nav-item-prev”> <figure class=”ct-media-container “><img width=”300″ height=”158″ src=”https://www.askpython.com/wp-content/uploads/2026/04/Pythonic_Way_of_Writing_Code_1777098780-300×158.png” class=”attachment-medium size-medium wp-post-image” alt=”” loading=”lazy” decoding=”async” srcset=”https://www.askpython.com/wp-content/uploads/2026/04/Pythonic_Way_of_Writing_Code_1777098780-300×158.png 300w, https://www.askpython.com/wp-content/uploads/2026/04/Pythonic_Way_of_Writing_Code_1777098780-1024×538.png 1024w, https://www.askpython.com/wp-content/uploads/2026/04/Pythonic_Way_of_Writing_Code_1777098780-768×403.png 768w, https://www.askpython.com/wp-content/uploads/2026/04/Pythonic_Way_of_Writing_Code_1777098780.png 1200w” sizes=”auto, (max-width: 300px) 100vw, 300px” itemprop=”image” style=”aspect-ratio: 1/1;” /><svg width=”20px” height=”15px” viewBox=”0 0 20 15″ fill=”#ffffff”><polygon points=”0,7.5 5.5,13 6.4,12.1 2.4,8.1 20,8.1 20,6.9 2.4,6.9 6.4,2.9 5.5,2 “/></svg></figure> <div class=”item-content”> <span class=”item-label”> Previous <span>Post</span> </span> <span class=”item-title ct-hidden-sm”> Pythonic Way of Writing Code </span> </div> </a> <a href=”https://www.askpython.com/python-modules/flask/flask-crud-application” class=”nav-item-next”> <div class=”item-content”> <span class=”item-label”> Next <span>Post</span> </span> <span class=”item-title ct-hidden-sm”> Flask CRUD Application – Create, Retrieve, Update, and Delete </span> </div> <figure class=”ct-media-container “><img width=”300″ height=”160″ src=”https://www.askpython.com/wp-content/uploads/2020/09/Flask-crud-300×160.png” class=”attachment-medium size-medium wp-post-image” alt=”Flask Crud” loading=”lazy” decoding=”async” srcset=”https://www.askpython.com/wp-content/uploads/2020/09/Flask-crud-300×160.png 300w, https://www.askpython.com/wp-content/uploads/2020/09/Flask-crud-1024×546.png 1024w, https://www.askpython.com/wp-content/uploads/2020/09/Flask-crud-768×410.png 768w, https://www.askpython.com/wp-content/uploads/2020/09/Flask-crud.png 1200w” sizes=”auto, (max-width: 300px) 100vw, 300px” itemprop=”image” style=”aspect-ratio: 1/1;” /><svg width=”20px” height=”15px” viewBox=”0 0 20 15″ fill=”#ffffff”><polygon points=”14.5,2 13.6,2.9 17.6,6.9 0,6.9 0,8.1 17.6,8.1 13.6,12.1 14.5,13 20,7.5 “/></svg></figure> </a> </nav>