当我与Python瞎搞,为什么float中的对象没有分母属性,而int呢?
>>> [attr for attr in dir(1) if not attr.startswith('_')]
['bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
>>> [attr for attr in dir(1.1) if not attr.startswith('_')]
['as_integer_ratio', 'conjugate', 'fromhex', 'hex', 'imag', 'is_integer', 'real']
虽然我明白,“结合”,“IMAG”和“真实”是为了与复杂类型兼容性的缘故,我不明白为什么“分子”和“分母”仅存在于int中,并不适用于float。
对此有何解释?
,你会想到什么'math.pi.denominator'返回? – dan04 2012-02-22 20:55:50
我会说7,但在维基百科之后,我明白pi是非理性的数字,并不完全等于22/7的理性版本。 – Radian 2012-02-22 21:29:43