国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

詳解Python3中ceil()函數用法

2020-02-16 01:14:36
字體:
來源:轉載
供稿:網友

描述

ceil(x) 函數返回一個大于或等于 x 的的最小整數。

語法

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

import mathmath.ceil( x )

注意:ceil()是不能直接訪問的,需要導入 math 模塊,通過靜態對象調用該方法。

參數

x -- 數值表達式。

返回值

函數返回返回一個大于或等于 x 的的最小整數。

實例

以下展示了使用 ceil() 方法的實例:

#!/usr/bin/python3import math  # 導入 math 模塊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(math.pi) : ", math.ceil(math.pi))

以上實例運行后輸出結果為:

math.ceil(-45.17) : -45math.ceil(100.12) : 101math.ceil(100.72) : 101math.ceil(math.pi) : 4

python 向上取整ceil 向下取整floor 四舍五入round

#encoding:utf-8import math#向上取整print "math.ceil---"print "math.ceil(2.3) => ", math.ceil(2.3)print "math.ceil(2.6) => ", math.ceil(2.6)#向下取整print "/nmath.floor---"print "math.floor(2.3) => ", math.floor(2.3)print "math.floor(2.6) => ", math.floor(2.6)#四舍五入print "/nround---"print "round(2.3) => ", round(2.3)print "round(2.6) => ", round(2.6)#這三個的返回結果都是浮點型print "/n/nNOTE:every result is type of float"print "math.ceil(2) => ", math.ceil(2)print "math.floor(2) => ", math.floor(2)print "round(2) => ", round(2)

運行結果:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇东市| 萨迦县| 昌吉市| 松桃| 嵊泗县| 平度市| 深泽县| 民丰县| 政和县| 钟祥市| 静海县| 滁州市| 九寨沟县| 霍州市| 浠水县| 溆浦县| 峨眉山市| 沾化县| 余姚市| 天镇县| 子长县| 林州市| 会理县| 尤溪县| 巍山| 芜湖市| 定远县| 临江市| 宜宾县| 奉新县| 林口县| 湖北省| 黑水县| 白玉县| 古浪县| 安岳县| 婺源县| 南川市| 山丹县| 富宁县| 宁夏|