Python program to calculate square of a given number Last Updated : 22 Feb, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The task of calculating the square of a number in Python involves determining the result of multiplying a number by itself. For example, given the number 4, its square is 16 because 4 × 4 = 16.Using ** operatorexponentiation operator (**) is the most direct and optimized way to compute powers. Since it is natively supported, it executes quickly with minimal overhead. Python n = 4 res = n ** 2 print(res) Output16 Using math.pow()math.pow() function provides a mathematical approach to computing squares. However, it returns a floating-point result, requiring conversion to an integer if needed. Python import math n = 4 res = math.pow(n, 2) print(int(res)) # Convert to int if needed Output16 Using * operatorA simple and efficient way to square a number is by multiplying it by itself. This method is straightforward and efficient for most cases. Python n = 4 res = n * n print(res) Output16 Using loopAn alternative method to calculate the square is by repeatedly adding the number to itself n times. While this works, it is not the best approach for squaring a number. Python n = 4 res = sum(n for _ in range(n)) print(res) Output16 Comment More infoAdvertise with us Next Article Python program to calculate square of a given number A aditya_taparia Follow Improve Article Tags : Technical Scripter Python Python Programs Technical Scripter 2020 Practice Tags : python Similar Reads Python Program to Find Cube of a Number We are given a number and our task is to find the cube of this number in Python. The cube of a number is calculated by multiplying the number by itself twice. For example, if the input is 3, then the output will be 3 * 3 * 3 = 27. In this article, we will learn different ways to find the cube of a n 2 min read Python program to find power of a number The task of finding the power of a number in Python involves calculating the result of raising a base number to an exponent. For example, if we have a base 2 and an exponent 3, the result is 2^3=8 .Using ** operatorThis is the simplest and most Pythonic way to calculate the power of a number. The ** 2 min read Find Square Root Of Given Number - Python Given an integer X, find its square root. If X is not a perfect square, then return floor(âx). For example, if X = 11, the output should be 3, as it is the largest integer less than or equal to the square root of 11.Using built-in functionsWe can also find the floor of the square root using Pythonâs 3 min read Python program to check if the given number is Happy Number A number is called happy if it leads to 1 after a sequence of steps wherein each step number is replaced by the sum of squares of its digit that is if we start with a Happy Number and keep replacing it with digits square sum, we reach 1. In this article, we will check if the given number is a Happy 4 min read Python Program to Find Area of Rectangle The task of calculating the Area of a Rectangle in Python involves taking the length and width as input, applying the mathematical formula for the area of a rectangle, and displaying the result.Area of Rectangle Formula :Area = Width * HeightWhere:Length is the longer side of the rectangle.Width is 2 min read Like