简单介绍Python中的floor()方法

yipeiwu_com5年前Python基础

 floor()方法返回不大于x的最大整数(向下取整)。
语法

以下是floor()方法的语法:

import math

math.floor( x )

注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。
参数

  •     x -- 这是一个数值表达式。

返回值

此方法返回不大于x的最大整数。
例子

下面的例子显示了floor()方法的使用。

#!/usr/bin/python
import math  # This will import math module

print "math.floor(-45.17) : ", math.floor(-45.17)
print "math.floor(100.12) : ", math.floor(100.12)
print "math.floor(100.72) : ", math.floor(100.72)
print "math.floor(119L) : ", math.floor(119L)
print "math.floor(math.pi) : ", math.floor(math.pi)

当我们运行上面的程序,它会产生以下结果:

math.floor(-45.17) : -46.0
math.floor(100.12) : 100.0
math.floor(100.72) : 100.0
math.floor(119L) : 119.0
math.floor(math.pi) : 3.0

相关文章

Python使用while循环花式打印乘法表

Python使用while循环花式打印乘法表

花式打印9*9乘法表 #第一个计数器 i = 1 while i < 10: #第二个计数器 j = 1 while j <= i: print('%...

python、PyTorch图像读取与numpy转换实例

Tensor转为numpy np.array(Tensor) numpy转换为Tensor torch.Tensor(numpy.darray) PIL.Image.Image转换成nu...

python实现最大子序和(分治+动态规划)

给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出:...

python+selenium select下拉选择框定位处理方法

一、前言 总结一下python+selenium select下拉选择框定位处理的两种方式,以备后续使用时查询; 二、直接定位(XPath) 使用Firebug找到需要定位到的元素,直接...

Tensorflow分类器项目自定义数据读入的实现

Tensorflow分类器项目自定义数据读入的实现

在照着Tensorflow官网的demo敲了一遍分类器项目的代码后,运行倒是成功了,结果也不错。但是最终还是要训练自己的数据,所以尝试准备加载自定义的数据,然而demo中只是出现了fas...