Python 如何使用内置的round()函数

Python 如何使用内置的round()函数,python,Python,我试图用下面的表达式求解?: round(5.18, ?) 结果应该是10.0 我曾想到过轮(5.18,print(10.0)),但事实并非如此,因为它给出了: 10.0 5 答案应该是10.0 因此python帮助说: Help on built-in function round in module builtins: round(number, ndigits=None) Round a number to a given precision in decimal digit

我试图用下面的表达式求解

round(5.18, ?)
结果应该是
10.0

我曾想到过
轮(5.18,print(10.0))
,但事实并非如此,因为它给出了:

10.0
5
答案应该是10.0


因此python帮助说:

Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.
因此,将ndigit设置为逗号后的-1位

>>> round(5.8, -1)
10.0

只需按如下方式编写:
round(5.8,-1)


并查看以了解有关内置圆形功能的更多信息。

无法将
5.18
圆形到
10.0
,它们之间的距离太远了!如果现在是
9.5-9.9
,这是可能的。谢谢!同时,我在另一台显示器上得出了这个结论:o有趣,但为什么要这样?@Copperfield根据:
返回的数字在小数点后四舍五入到ndigits精度。。。任何整数值对ndigit(正、零或负)都有效。
是的,我也读过文档,但对我来说仍然没有意义……我想我现在明白了,就像先将其除以10,然后再将其四舍五入,再乘以10一样
>>> round(5.8, -1)
10.0