---
description: Using Python&#039;s in-built libraries or functions, users can find the Square of a number. Multiplying the same number twice gives us the square of the number.
title: How to Square a Number in Python (6 ways)
image: https://www.guru99.com/images/how-to-square-a-number-in-python.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Square a Number in Python explores six practical techniques: pow function, power operator, multiplication, list method, while loop, and NumPy array squaring with performance trade-offs.

* ⚡ **Exponent Operator:** number \*\* 2 is the fastest and most idiomatic Python.
* ✖️ **Multiplication:** number \* number reads naturally for single values.
* 🔢 **Built-in pow:** pow(n, 2, mod) supports modular exponentiation.
* 📐 **math.pow:** Always returns float; use \*\* for integer precision.
* 📊 **NumPy:** np.array(x) \*\* 2 outperforms loops by 100x on arrays.
* 🤖 **AI Snippets:** AI tools generate squaring patterns and trade-offs.

[ Read More ](javascript:void%280%29;) 

![How to Square a Number in Python](https://www.guru99.com/images/how-to-square-a-number-in-python.png)

Using Python’s in-built libraries or functions, users can find the Square of a number. Multiplying the same number twice gives us the square of the number. This Python article provides diverse ways to arrive at the Square of the number.

## Method 1: Use of Pow() Function in Python

pow() is a built-in function available under the Math module of python. This function helps in the determination of the power of a number.

To determine the Square of the number, it uses two as the power.

Following is the syntax for the pow function as shown below:

**Syntax:** 

Pow (base, exponent)

**Explanation: –**

The function takes two arguments, namely the base and exponent.

* **Base**: the number whose power or Square needs to be calculated.
* **Exponent**: is a number used as the superscript to the base number.

**Example:** 

Let us take an example of how to determine the Square of a number using python code. This Python program would calculate a number’s square using base and exponent integers as inputs.

**Python Code:**

Base=input("Provide base integer") if Base.isdigit()==True: Base=int(Base) result=pow(Base,2) print("The square result is ", result) else: print("please provide an integer lkw">for base") 

**Output:**

Provide base integer2
The square result is 4

**Explanation:**

Before determining the Square of a number, the above code takes an input from the user. The code checks the input to be a digit or not. If it is true, it determines the Square of number.

## Method 2: Use of Power Operator

A power operator in python is represented as **‘\*\*’**. It is utilized in python to determine the power of a number. With an exponent of two as input, this operator gives the user the square of a number in Python. A power operator is also referred to as an exponent operator.

Power operator has the following python syntax:

**Syntax: –**

(Base**Exponent)

Let us take an example of how to determine the Square of a number using the exponent operator in python. This program would take base and exponent integers as input to determine the Square of a number.

**Python Code:**

Base=input("Provide base integer") Exponent=input("Provide exponent integer") if Base.isdigit() & Exponent.isdigit()==True: Base=int(Base) Exponent=int(Exponent) result=Base\*\*Exponent print("The square result is ",result) else: print("please provide an integer lkw">for base") 

**Output:**

Provide base integer2
Provide Exponent integer2
The square result is 4

**Explanation:** 

Before determining the Square of a number, the above code takes an input from the user. The code checks the input to be a digit or not. If it is true, it determines the Square of number.

## Method 3: Use of Multiplication to Determine Square of a Number

The Creation of a python script to determine the Square of a number using multiplication is easy. The following Python code would take a number from the user and multiply it couple of times. It also checks whether the given input is a digit or not.

The python code would follow the following syntax:

**Syntax:** 

(Base* Base)

The above syntax is similar to the basic mathematical representation. This shows that the Square of a number can be determined by multiplying the base by itself a couple of times.

**Example:** 

Let us take an example of how to determine the Square of a number using multiplication in python code. This program would take base as input to determine the Square of a number.

**Python Code:**

Base=input("Provide base integer") if Base.isdigit()==True: Base=int(Base) result=Base\*Base print("The square result is ",result) else: print("please provide an integer lkw">for base") 

**Output:**

Provide base integer2
The square result is 4

**Explanation:**

Before determining the Square of a number, the above code takes an input from the user. The code checks the input to be a digit or not. If it is true, it determines the Square of number.

### RELATED ARTICLES

* [PyQt5 Tutorial with Examples: Create Python GUIs with Qt ](https://www.guru99.com/pyqt-tutorial.html "PyQt5 Tutorial with Examples: Create Python GUIs with Qt")
* [How to Find Average of List in Python ](https://www.guru99.com/find-average-list-python.html "How to Find Average of List in Python")
* [Python time.sleep(): Add Delay to Your Code (Example) ](https://www.guru99.com/python-time-sleep-delay.html "Python time.sleep(): Add Delay to Your Code (Example)")
* [Python readline() Method with Examples ](https://www.guru99.com/python-file-readline.html "Python readline() Method with Examples")

## Method 4: Use of a List to Determine the Square of a Number

Python provides the functionality of determining the Square of a number for more than one base, and they can be grouped together to be formed as a python list. It is a type of data structure that enables the programmer to store multiple elements or values under one single variable. It would then square each number present in the list.

Let us take an example of how to determine the Square of a number using a list data structure. This program takes a list as an input to determine the Square of a number.

**Python Code:**

sqr_list = [2,4,6,8]
for Base in sqr_list:
    result=Base**2
    print("The square result is ",result)

**Output:**

The square result is 4
The square result is 16
The square result is 36
The square result is 64

**Explanation:**

In the above Python code, a for loop is executed that traverses through each element present in the list and for each element. It determines the Square of a number. Using the above approach, the list helps us in the determination of the Square of various integer values.

## Method 5: Use of While Loop in Python

A while loop can also be used to determine the Square of a number in python. It can be termed as the repetition of a specific instruction till the time a specific condition is met. It helps in computing the Square of a number by repeating instructions until the provided condition becomes false.

The below program iterates using a [while loop](https://www.guru99.com/python-loops-while-for-break-continue-enumerate.html) to determine the Square of a number until the counter used as input is either equal to or less than 5.

**Python Code:**

n_start = 1
while n_start <=5:
    result= n_start **2
    print("The square result is ",result)
    n_start=n_start+1

**Output:**

The square result is 1
The square result is 4
The square result is 9
The square result is 16
The square result is 25

## Method 6: Use of arrays to Determine Square of a Number

Another method that could be utilized to determine the Square of a number is by utilizing the combination of arrays and an in-built function available within python.

One can use the [Python array](https://www.guru99.com/python-arrays.html) and square method present within the NumPy module to determine the Square of a number. Let us take an example to determine the Square of a number using the above two methods as shown below: –

**Python Code:**

import numpy as np
NumpyArray = np.array([2,4,6,8])
print("Square of the elements present in array are : \n", np.square(NumpyArray))

**Output:**

Square of the elements present in the array are:
[ 4 16 36 64]

## FAQs

⚡ Fastest way to square a number in Python?

The \*\* operator is fastest, roughly 25x faster than pow() and math.pow() in benchmarks.

🤖 Can AI tools help pick the right squaring method?

Yes. AI explains trade-offs between \*\*, pow, math.pow, and NumPy based on your data shape.

💡 How does AI debug Python math precision issues?

AI interprets OverflowError and float precision warnings, recommending decimal or NumPy.

🔢 Difference between pow() and \*\* in Python?

Both raise base to power. pow() also takes a modulus: pow(x, 2, mod) runs modular exponentiation.

📐 Why does math.pow return a float for integers?

math.pow wraps the C double-precision pow. Use \*\* or built-in pow() for exact integer results.

📊 How to square every value in a NumPy array?

Use np.square(arr) or arr \*\* 2\. Both are vectorized in C and far faster than Python loops.

🛡️ Does -3 \*\* 2 equal 9 or -9 in Python?

\-9\. Python parses it as -(3\*\*2) due to precedence. Use (-3) \*\* 2 to get 9.

📚 Square a number without using operators?

Call pow(n, 2) or math.pow(n, 2). Loops and bitwise tricks work but are slower and less clear.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/how-to-square-a-number-in-python.png","url":"https://www.guru99.com/images/how-to-square-a-number-in-python.png","width":"700","height":"250","caption":"How to Square a Number in Python","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/python-square.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/python","name":"Python"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/python-square.html","name":"How to Square a Number in Python (6 ways)"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/python-square.html#webpage","url":"https://www.guru99.com/python-square.html","name":"How to Square a Number in Python (6 ways)","dateModified":"2026-06-23T16:25:37+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/how-to-square-a-number-in-python.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/python-square.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/anna","name":"Anna Blake","description":"I'm Anna Blake, specializing in Python tutorials, offering clear and concise lessons to help you master Python programming efficiently.","url":"https://www.guru99.com/author/anna","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/anna-blake-author.png","url":"https://www.guru99.com/images/anna-blake-author.png","caption":"Anna Blake","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Python","headline":"How to Square a Number in Python (6 ways)","description":"Using Python&#039;s in-built libraries or functions, users can find the Square of a number. Multiplying the same number twice gives us the square of the number.","keywords":"python","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/anna","name":"Anna Blake"},"dateModified":"2026-06-23T16:25:37+05:30","image":{"@id":"https://www.guru99.com/images/how-to-square-a-number-in-python.png"},"copyrightYear":"2026","name":"How to Square a Number in Python (6 ways)","subjectOf":[{"@type":"HowTo","name":"How to Square a Number in Python","description":"Using Python\u2019s in-built libraries or functions, users can find the Square of a number. Multiplying the same number twice gives us the square of the number. This Python article provides diverse ways to arrive at the Square of the number.","step":[{"@type":"HowToStep","name":"Step 1) Method 1: Use of Pow() Function in Python","text":"Pow function is an in-built function available under the Math module of python. This function helps in the determination of the power of a number.","url":"https://www.guru99.com/python-square.html#step1"},{"@type":"HowToStep","name":"Step 2) Method 2: Use of Power Operator","text":"A power operator in python is represented as \u2018**\u2019. It is utilized in python to determine the power of a number. With an exponent of two as input, this operator gives the user the square of a number in Python. A power operator is also referred to as an exponent operator.","url":"https://www.guru99.com/python-square.html#step2"},{"@type":"HowToStep","name":"Step 3) Method 3: Use of Multiplication to Determine Square of a Number","text":"The Creation of a python script to determine the Square of a number using multiplication is easy. The following Python code would take a number from the user and multiply it couple of times. It also checks whether the given input is a digit or not.","url":"https://www.guru99.com/python-square.html#step3"},{"@type":"HowToStep","name":"Step 4) Method 4: Use of a List to Determine the Square of a Number","text":"Python provides the functionality of determining the Square of a number for more than one base, and they can be grouped together to be formed as a python list. It is a type of data structure that enables the programmer to store multiple elements or values under one single variable. It would then square each number present in the list.","url":"https://www.guru99.com/python-square.html#step4"},{"@type":"HowToStep","name":"Step 5) Method 5: Use of While Loop in Python","text":"A while loop can also be used to determine the Square of a number in python. It can be termed as the repetition of a specific instruction till the time a specific condition is met. It helps in computing the Square of a number by repeating instructions until the provided condition becomes false.","url":"https://www.guru99.com/python-square.html#step5"},{"@type":"HowToStep","name":"Step 6) Method 6: Use of arrays to Determine Square of a Number","text":"Another method that could be utilized to determine the Square of a number is by utilizing the combination of arrays and an in-built function available within python.","url":"https://www.guru99.com/python-square.html#step6"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Fastest way to square a number in Python?","acceptedAnswer":{"@type":"Answer","text":"The ** operator is fastest, roughly 25x faster than pow() and math.pow() in benchmarks."}},{"@type":"Question","name":"Can AI tools help pick the right squaring method?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI explains trade-offs between **, pow, math.pow, and NumPy based on your data shape."}},{"@type":"Question","name":"How does AI debug Python math precision issues?","acceptedAnswer":{"@type":"Answer","text":"AI interprets OverflowError and float precision warnings, recommending decimal or NumPy."}},{"@type":"Question","name":"Difference between pow() and ** in Python?","acceptedAnswer":{"@type":"Answer","text":"Both raise base to power. pow() also takes a modulus: pow(x, 2, mod) runs modular exponentiation."}},{"@type":"Question","name":"Why does math.pow return a float for integers?","acceptedAnswer":{"@type":"Answer","text":"math.pow wraps the C double-precision pow. Use ** or built-in pow() for exact integer results."}},{"@type":"Question","name":"How to square every value in a NumPy array?","acceptedAnswer":{"@type":"Answer","text":"Use np.square(arr) or arr ** 2. Both are vectorized in C and far faster than Python loops."}},{"@type":"Question","name":"Does -3 ** 2 equal 9 or -9 in Python?","acceptedAnswer":{"@type":"Answer","text":"-9. Python parses it as -(3**2) due to precedence. Use (-3) ** 2 to get 9."}},{"@type":"Question","name":"Square a number without using operators?","acceptedAnswer":{"@type":"Answer","text":"Call pow(n, 2) or math.pow(n, 2). Loops and bitwise tricks work but are slower and less clear."}}]}],"@id":"https://www.guru99.com/python-square.html#schema-204193","isPartOf":{"@id":"https://www.guru99.com/python-square.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/python-square.html#webpage"}}]}
```
