ceil()函數,用於返回數字的上入整數。前端
本人在用python作web網站,後端作到翻頁功能的時候,會用到math.ceil()函數來實現。python
好比:web
前端規定每頁的數據爲20條:size=20數據庫
後端從數據庫取到符合條件的總數據爲:count=50後端
這樣獲得的頁數max_page應該是3頁(count/size=2.5, 取上入整數即整數3),須要用到math中的ceil來實現。函數
輸入代碼:網站
# python的內建函數ceil() import math print(math.ceil(-14.5)) print(math.ceil(50)) print(math.ceil(60.2)) print(math.ceil(math.pi))
輸出:import