1. 向下取整:使用 `int()` 函数。
x = 3.5
y = int(x)
print(y) 输出为 3
2. 四舍五入:使用 `round()` 函数。
x = 3.5
y = round(x)
print(y) 输出为 4
3. 向上取整:使用 `math.ceil()` 函数,需要先导入 `math` 模块。
import math
x = 3.5
y = math.ceil(x)
print(y) 输出为 4
请根据你的具体需求选择合适的方法来取整