x = 3.5
y = int(x)
print(y) 输出为 3
2. 使用 `math` 模块中的 `floor()` 函数进行向下取整:
import math
x = 3.5
y = math.floor(x)
print(y) 输出为 3
3. 使用 `math` 模块中的 `ceil()` 函数进行向上取整:
import math
x = 3.5
y = math.ceil(x)
print(y) 输出为 4
4. 使用 `round()` 函数对浮点数进行四舍五入,然后再转换为整数:
x = 3.5
y = round(x)
print(y) 输出为 4
根据你的具体需求选择适合的方法来保留整数