今天摸鱼水段子时,在/r/ProgrammerHumor/上发现一个有意思的现象 熟悉Python的同学可能都踩过坑,但我确实是第一次知道这个现象,于是我在本地试了一下,发现确实如此,于是我求助于谷歌,并最终在Python的官方文档里找到了解释 Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). Any integer value is valid for ndigits (positive, zero, or negative). The return value is an integer if ndigits is omitted or None. Otherwise, the return value has the same type as number. ...

January 3, 2023 · 1 min · ChaosNyaruko