[Python-ideas] `numbers.Natural`
David Mertz
mertz at gnosis.cx
Fri Sep 26 22:38:01 CEST 2014
On Fri, Sep 26, 2014 at 1:27 PM, Ian Cordasco <graffatcolmingov at gmail.com>
wrote:
>
> The only motivations I can think of for making this a type (not that
> they're good ones) is you could do something like:
>
> if isinstance(x, (Natural, Complex, Real)):
> #
> elif isinstance(x, Rational):
> #
> else:
> raise ValueError
>
This code seems a bit broken, given:
>>> issubclass(numbers.Rational, numbers.Real)
Out[3]: True
> def isNatural(x):
> return isinstance(x, int) and x > 0
>
I think the original desired behavior is this different one-liner:
isNatural = lambda x: int(x)==x and x>0
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140926/4424ef00/attachment.html>
More information about the Python-ideas
mailing list