[Python-ideas] isinstance(Decimal(), Real) -> False?
Steven D'Aprano
steve at pearwood.info
Wed Aug 28 10:38:12 CEST 2013
On Wed, Aug 28, 2013 at 10:25:42AM +0200, Michele Lacchia wrote:
> How can isinstance(d, Real) imply isinstance(d, Complex)? Can you elaborate
> a little more?
> It makes no sense to me, since the set of real numbers is a subset of the
> complex one.
You've just explained it. Since real numbers are a subset of complex
numbers, every real number is a complex number with the imaginary part
set to zero.
py> import numbers
py> isinstance(42.0, numbers.Complex)
True
py> (42.0).imag
0.0
This only applies with abstract base classes like numbers.Complex, not
concrete classes like complex.
py> isinstance(42.0, complex)
False
--
Steven
More information about the Python-ideas
mailing list