溫馨提示×

python的math庫中的函數有哪些

九三
1840
2021-02-12 14:52:00
欄目: 編程語言

python的math庫中的函數有哪些

python中常用的math庫函數有以下幾種

1.math.ceil

取大于等于x的最小的整數值,如果x是一個整數,則返回x

>>> math.ceil(4.12)

5

2.math.copysign

把y的正負號加到x前面,可以使用0

>>> math.copysign(2,-3)

-2.0

3.math.cos

求x的余弦,x必須是弧度

>>> math.cos(math.pi/4)

0.7071067811865476

4.math.degrees

把x從弧度轉換成角度

>>> math.degrees(math.pi/4)

45.0

5.math.gcd

返回x和y的最大公約數

>>> math.gcd(8,6)

2

6.math.exp

exp()返回math.e(其值為2.71828)的x次方

>>> math.exp(2)

7.38905609893065

7.math.expm1

expm1()返回math.e的x(其值為2.71828)次方的值減1

>>> math.expm1(2)

6.38905609893065

8.math.fabs

fabs()返回x的絕對值

>>> math.fabs(-0.03)

0.03

9.math.factorial

factorial()取x的階乘的值

>>> math.factorial(3)

6

10.math.floor

floor()取小于等于x的最大的整數值,如果x是一個整數,則返回自身

>>> math.floor(4.999)

4

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女