gpt4 book ai didi

Python Decimal 类型不是 Real?

转载 作者:行者123 更新时间:2023-12-01 09:01:49 25 4
gpt4 key购买 nike

考虑以下因素:

from decimal import Decimal
from numbers import Number, Complex, Real

z = Decimal(0)

# Expected: a == b == c == True
# Actual (Python 3.6.5):
a = isinstance(z, Number) # True
b = isinstance(z, Complex) # False
c = isinstance(z, Real) # False

Decimal似乎实现了需要考虑的一切Real根据PEP3141 ,那么什么给出呢?值得注意的是,fractions.Fraction已按上述代码片段正确分类(例如 a == b == c == True )。

最佳答案

这实际上在PEP 3141中提到过:

After consultation with its authors it has been decided that the Decimal type should not at this time be made part of the numeric tower.

因此故意排除了十进制

关于Python Decimal 类型不是 Real?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com