[Python-ideas] isinstance(Decimal(), Real) -> False?
Michele Lacchia
michelelacchia at gmail.com
Wed Aug 28 11:34:58 CEST 2013
Damn, it seems that my mind was filled by some kind of fog...
Ehm, I now get it, sorry. I really don't know what was passing in my mind
before.
On Wed, Aug 28, 2013 at 10:38 AM, Steven D'Aprano <steve at pearwood.info>wrote:
> 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
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
--
Michele Lacchia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130828/40e5b070/attachment.html>
More information about the Python-ideas
mailing list