How to Square in Python

Techwalla may earn compensation through affiliate links in this story.

The open source programming language, Python, contains a math module, which returns the values for many common mathematical expressions and trigonometric functions. You can determine the square root of any number by loading the "math" module and running the square root function.


Step 1

Open your Python editor.

Video of the Day

Step 2

Type "from math import sqrt", then press "Enter." This loads the Python math module and the square root function.

Step 3

Type "print sqrt (root)" then press "Enter." Python calculates the square root and displays it on the next line.


"Root" is the number that you wish to calculate the square root. For example, "print sqrt (49) returns the number "7."