共計(jì) 274 個(gè)字符,預(yù)計(jì)需要花費(fèi) 1 分鐘才能閱讀完成。
在 Python 中,可以使用以下方法進(jìn)行向下取整:
- 使用整除操作符
//
,它將結(jié)果截?cái)酁樽罱咏男∮诨虻扔谠贾档恼麛?shù)。
x = 7.8
y = x // 1
print(y) # 輸出: 7
- 使用
math.floor()
函數(shù),它返回不大于輸入?yún)?shù)的最大整數(shù)。
import math
x = 7.8
y = math.floor(x)
print(y) # 輸出: 7
- 使用
numpy.floor()
函數(shù),它返回不大于輸入?yún)?shù)的最大整數(shù)。
import numpy as np
x = 7.8
y = np.floor(x)
print(y) # 輸出: 7.0
這些方法可以根據(jù)具體的需求選擇使用。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完