How about adding rational fraction to Python?

Paul Rubin http
Wed Feb 27 00:41:16 EST 2008


Mark Dickinson <dickinsm at gmail.com> writes:
> > So use:  return sum(number_list) / float(len(number_list))
> > That makes it somewhat more explicit what you want.  Otherwise
> 
> But that fails for a list of Decimals...

Again, that depends on what your application considers to be failure.
Heck, int/int = float instead of decimal might be a failure.

FWIW, I just checked Haskell: int/int is not allowed (compile time
type error).  There is an integer division function `div`, like
Python's //, . that you can use if you want an integer quotient. If
you want a floating or rational quotient, you have to coerce the
operands manually.  Explicit is better than implicit.



More information about the Python-list mailing list