26 Sep
2014
26 Sep
'14
10:33 p.m.
On 09/26/2014 01:27 PM, Ian Cordasco 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
Which is naturally (no pun intended) slightly nicer than
if isinstance(x, (Complex, Real)) or isNatural(x): #
The Good Reason for having a Natural type would be not having to always check for illegal values -- if one is (attempted to be) created, an exception is raised on the spot. n5 = Natural(5) n7 = Natural(7) n5 - n7 Traceback... -- ~Ethan~