python——数学模块(math模块)(2)

简介: python——数学模块(math模块)(2)

pow(x, y)

返回 x 的 y 次幂。看下示例:

import math
x = 3
y = 2
print(math.pow(x, y))

fsum(iterable)

返回迭代器中所有元素的和。看下示例:

import math
print(math.fsum((1, 2, 3, 4, 5)))

gcd(x, y)

返回整数 x 和 y 的最大公约数。看下示例:

import math
x = 9
y = 6
print(math.gcd(x, y))

sqrt(x)

返回 x 的平方根。看下示例:

import math
x = 9
print(math.sqrt(x))


trunc(x)

返回 x 的整数部分。看下示例:

import math
x = 1.1415926
print(math.trunc(x))

exp(x)

返回 e 的 x 次幂。看下示例:

import math
x = 2
print(math.exp(2))

log(x[, base])

返回 x 的对数,底数默认为 e。看下示例:

import math
x = 10
y = 10
# 不指定底数
print(math.log(x))
# 指定底数
print(math.log(x, y))


相关文章
|
1天前
|
Python Windows
python中的异常与模块
python中的异常与模块
8 1
|
10天前
|
JSON 数据格式 Python
Python标准库中包含了json模块,可以帮助你轻松处理JSON数据
【4月更文挑战第30天】Python的json模块简化了JSON数据与Python对象之间的转换。使用`json.dumps()`可将字典转为JSON字符串,如`{"name": "John", "age": 30, "city": "New York"}`,而`json.loads()`则能将JSON字符串转回字典。通过`json.load()`从文件读取JSON数据,`json.dump()`则用于将数据写入文件。
16 1
|
11天前
|
Python
Python实现压缩解压---tarfile模块详解
Python实现压缩解压---tarfile模块详解
|
11天前
|
Linux Python Windows
Python中time和datetime模块详解
Python中time和datetime模块详解
|
12天前
|
存储 Linux 数据安全/隐私保护
python的压缩模块zipfile详解
python的压缩模块zipfile详解
|
12天前
|
Linux Python Windows
python的os模块详细解读(二)
python的os模块详细解读(二)
|
12天前
|
移动开发 Linux Shell
python的os模块详细解读(一)
python的os模块详细解读(一)
python的os模块详细解读(一)
|
12天前
|
Python 容器
python内置函数、数学模块、随机模块(二)
python内置函数、数学模块、随机模块(二)
|
12天前
|
索引 Python
python内置函数、数学模块、随机模块(一)
python内置函数、数学模块、随机模块(一)
|
12天前
|
容器
【Python21天学习挑战赛】-迭代器 & f-格式化 & 模块
【Python21天学习挑战赛】-迭代器 & f-格式化 & 模块