Python中的ceil()方法使用教程

yipeiwu_com5年前Python基础

 ceil()方法返回x的值上限 - 不小于x的最小整数。
语法

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

import math

math.ceil( x )

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

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

返回值

此方法返回不小于x的最小整数。
示例

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

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

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

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

math.ceil(-45.17) : -45.0
math.ceil(100.12) : 101.0
math.ceil(100.72) : 101.0
math.ceil(119L) : 119.0
math.ceil(math.pi) : 4.0


相关文章

Python简单读写Xls格式文档的方法示例

Python简单读写Xls格式文档的方法示例

本文实例讲述了Python简单读写Xls格式文档的方法。分享给大家供大家参考,具体如下: 1. 模块安装 使用pip install命令安装, 即: pip install xlrd...

python直接访问私有属性的简单方法

实例化对象名._类名__私有属性名 class Flylove: price = 123 def __init__(self): self.__d...

初探利用Python进行图文识别(OCR)

初探利用Python进行图文识别(OCR)

话说什么是OCR????? 简介 OCR技术是光学字符识别的缩写(Optical Character Recognition),是通过扫描等光学输入方式将各种票据、报刊、书籍、文稿及其...

在GitHub Pages上使用Pelican搭建博客的教程

在GitHub Pages上使用Pelican搭建博客的教程

Pelican 介绍 首先看看 Pelican 的一些主要特性:     Python实现,开放源码     输出静...

Pytorch提取模型特征向量保存至csv的例子

Pytorch提取模型特征向量 # -*- coding: utf-8 -*- """ dj """ import torch import torch.nn as nn impor...