python标准库math中计算平方根的函数_16 Python 标准库之 math 模块 - Python 进阶应用教程...

1. 前言

math 模块中包含了各种浮点运算函数,包括:

函数

功能

floor

向下取整

ceil

向上取整

pow

指数运算

fabs

绝对值

sqrt

开平方

modf

拆分小数和整数

fsum

计算列表中所有元素的累加和

copysign

复制符号

pi

圆周率

e

自然对数

2. math.floor(n)

函数 math.floor(n) 的功能是对浮点数 n 向下取整,示例如下:

>>> import math

>>> math.floor(1.5)

1

>>> math.floor(2.5)

2

>>> math.floor(-1.5)

-2

>>> math.floor(-2.5)

-3

3. math.ceil(n)

函数 math.ceil(n) 的功能是对浮点数 n 向上取整,示例如下:

>>> import math

>>> math.ceil(1.5)

2

>>> math.ceil(2.5)

3

>>> math.ceil(-1.5)

-1

>


版权声明:本文为weixin_31342203原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。