python / beginner
Snippet
Basic Math Functions
Python's standard library includes a 'math' module for advanced calculations. The sqrt() function specifically calculates the square root of a number.
snippet.py
1
2
3
4
import mathnumber = 25result = math.sqrt(number)print(result)
Breakdown
1
import math
Brings the math module into your script so you can use its tools.
2
result = math.sqrt(number)
Uses the square root function from the math module on the variable 'number'.
3
print(result)
Outputs the result of the calculation (5.0).