python math.floor()方法

math.floor()方法

python math模块floor()方法,可以返回一个小于等于参数的最大整数值。


floor()语法

floor(x, /)

python源码对floor()方法的介绍:

    Return the floor of x as an Integral.
    
    This is the largest integer <= x.

参数

参数描述
xreal number,如果不是数值,python将抛出TypeError。

返回值

python int整型数值。


math.floor()实例代码

>>> import math
>>> math.floor(1.99999999)
1
>>> math.floor(0.1)
0
>>> math.floor('1.5')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not str
>>> math.floor([5.6])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not list

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.