We'll learn how to square a number in Python. We can achieve this using a multiplication operator, an inbuilt function, or using an exponent operator.
We can get the square of a number by multiplying the number by itself.
#given number num = 10 #square of given number print(num*num)
math.pow()
methodWe can get the square of a number using the pow()
method provided by the math
module. We'll pass the number to the first parameter and 2
to the second parameter to get the square of the number.
import math #given number num = 10 #get square of a number print(math.pow(10,2))
math
, which provides the pow()
method.pow()
method to get the square of the given number, num
, by passing the number num
as the first parameter and 2
as the second parameter, and then we'll print the returned result.We can get the square of a number in python using the exponent operator(**) if we provide the exponent value as 2
.
#given number num = 10 #square of given number using exponent operator print(num**2)
2
and display it.RELATED TAGS
CONTRIBUTOR
View all Courses