Python基础 之 Python math 模块

简介: Python math 模块

Python基础 之 Python math 模块

Python math 模块

Python math 模块提供了许多对浮点数的数学运算函数。

math 模块下的函数,返回值均为浮点数,除非另有明确说明。

如果你需要计算复数,请使用 cmath 模块中的同名函数。

要使用 math 函数必须先导入:

import math

查看 math 模块中的内容:

import math
dir(math)
['doc', 'file', 'loader', 'name', 'package', 'spec', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']

math 模块常量

常量 描述

math.e 返回欧拉数 (2.7182...)
math.inf 返回正无穷大浮点数
math.nan 返回一个浮点值 NaN (not a number)
math.pi π 一般指圆周率。 圆周率 PI (3.1415...)
math.tau 数学常数 τ = 6.283185...,精确到可用精度。Tau 是一个圆周常数,等于 2π,圆的周长与半径之比。

目录
相关文章
|
6天前
|
Python
【Python进阶(五)】——模块搜索及工作目录
【Python进阶(五)】——模块搜索及工作目录
|
1天前
|
运维 网络安全 Python
使用Python http.server模块共享文件
今天给大家介绍一下Python标准库中的http.server模块。这个模块提供了一种简单的方式来快速启动一个HTTP服务器,非常适合临时共享文件、测试、教学等轻量级场景。
|
1天前
|
数据采集 数据挖掘 Python
2024年最新【Python从零到壹】Python模块介绍与使用,面试的时候答不上来
2024年最新【Python从零到壹】Python模块介绍与使用,面试的时候答不上来
2024年最新【Python从零到壹】Python模块介绍与使用,面试的时候答不上来
|
1天前
|
Python
2024年最新【Python从零到壹】Python模块介绍与使用(1),2024年最新阿里面试场景题
2024年最新【Python从零到壹】Python模块介绍与使用(1),2024年最新阿里面试场景题
2024年最新【Python从零到壹】Python模块介绍与使用(1),2024年最新阿里面试场景题
|
1天前
|
机器学习/深度学习 数据采集 自然语言处理
[python][whl]python模块triton的whl文件下载地址汇总(1)
[python][whl]python模块triton的whl文件下载地址汇总(1)
|
4天前
|
Python
【Python3 查询手册学习】,完整版PDF开放下载_python速查手册·模块卷(全彩版) pdf(1)
【Python3 查询手册学习】,完整版PDF开放下载_python速查手册·模块卷(全彩版) pdf(1)
|
4天前
|
Python
Python基础教程: math库常用函数(1),Python这些高端技术只有你还不知道
Python基础教程: math库常用函数(1),Python这些高端技术只有你还不知道
|
5天前
|
Python
Python使用typing模块(从Python 3.5开始)
【5月更文挑战第10天】Python使用typing模块(从Python 3.5开始)
13 3
|
6天前
|
Python
在Python中,利用`os模块`的`path.exists()`函数可判断文件是否存
【5月更文挑战第12天】在Python中,利用`os模块`的`path.exists()`函数可判断文件是否存在,该函数对路径进行检查,存在则返回True,不存在则返回False。示例代码展示了如何检查'example.txt'文件是否存在并相应打印消息。此外,`os.path.isfile()`用于确认路径是否为文件,仅当是文件时返回True,否则返回False,同样配以示例说明其用法。
23 2
|
6天前
|
Python Windows
python中的异常与模块
python中的异常与模块
13 1