# Python数学模块用法介绍

## 本文概述

Python数学模块被定义为最受欢迎的数学函数, 其中包括三角函数, 表示函数, 对数函数等。此外, 它还定义了两个数学常数, 即Pie和Euler数等。

Pie(n)：这是众所周知的数学常数, 定义为环境与圆直径的比率。其值为3.141592653589793。

## math.log()

``````import math
number = 2e-7  # small value of of x
print('log(fabs(x), base) is :', math.log(math.fabs(number), 10))``````

``log(fabs(x), base) is : -6.698970004336019``

## math.log10()

``````import math
x=13  # small value of of x
print('log10(x) is :', math.log10(x))``````

``log10(x) is : 1.1139433523068367``

## math.exp()

``````import math
number = 5e-2  # small value of of x
print('The given number (x) is :', number)
print('e^x (using exp() function) is :', math.exp(number)-1)``````

``````The given number (x) is : 0.05
e^x (using exp() function) is : 0.05127109637602412``````

## math.sqrt()

``````import math
x = 20
y = 14
z = 17.8995
print('sqrt of 20 is ', math.sqrt(x))
print('sqrt of 14 is ', math.sqrt(y))
print('sqrt of 17.8995 is ', math.sqrt(z))``````

``````sqrt of 20 is 4.47213595499958
sqrt of 14 is 3.7416573867739413
sqrt of 17.8995 is 4.230780069916185``````

## math.expm1()

``````import math
number = 2e-1  # small value of of x
print('The given number (x) is :', number)
print('e^x (using expml() function) is :', math.expm1(number))``````

``````The given number (x) is : 0.2
e^x (using expml() function) is : 0.22140275816016985``````

## math.cos()

``````import math
angleInDegree = 60
angleInRadian = math.radians(angleInDegree)
print('Given angle :', angleInRadian)
print('cos(x) is :', math.cos(angleInRadian))``````

``````Given angle : 1.0471975511965976
cos(x) is : 0.5000000000000001``````

## math.sin()

``````import math
angleInDegree = 60
angleInRadian = math.radians(angleInDegree)
print('Given angle :', angleInRadian)
print('sin(x) is :', math.sin(angleInRadian))``````

``````Given angle : 1.0471975511965976
sin(x) is : 0.8660254037844386``````

## math.tan()

``````import math
angleInDegree = 60
angleInRadian = math.radians(angleInDegree)
print('Given angle :', angleInRadian)
print('tan(x) is :', math.tan(angleInRadian))``````

``````Given angle : 1.0471975511965976
tan(x) is : 1.7320508075688767``````

• 回顶