Python math Functions – This Python tutorial will explain the use of Python math functions in Python Programs with example Python scripts and their output.
What is a Python math Module?
The Python programming language has a math module. The math module contains different functions for general math calculations.
What are different math functions?
There many math functions present in math module. For example, the math module contains the following functions:
sqrt() function
factorial() function
pow() function
exp() function
log() function
log10() function
sin() function
cos() function
tan() function
floor() function
ceil() function etc.
How we can use math module and its functions?
We must import the math module in our Python program. Then we can use math functions.
What is Python import statement?
import statement is used to import standard modules of Python.
For example to import math module, we will write import statement as follows:
import math
Use and Examples of Math Functions
# This Python program show the use of # different math functions present in # Python math module. We first import # math modue # Author: www.EasyCodeBook.com import math c = math.ceil(7.4) print('ciel(7.4)=',c) f = math.floor(7.4) print('floor(7.4)=',f) s = math.sqrt(25) print('sqrt(25)=',s) f = math.factorial(4) print('factorial(4)=',f) p = pow(2,3) print('pow(2,3)=',p) a = abs(-5.50) print('abs(-5.50)=',a) s = math.sin(0) print('sin(0)=',s) c = math.cos(0) print('cos(0)=',c) t = math.tan(0) print('tan(0)=',t)
The output will be: ciel(7.4)= 8 floor(7.4)= 7 sqrt(25)= 5.0 factorial(4)= 24 pow(2,3)= 8 abs(-5.50)= 5.5 sin(0)= 0.0 cos(0)= 1.0 tan(0)= 0.0
Pingback: Python Functions Defining and Using Functions | EasyCodeBook.com