Pep 238 Why new // operator (Non-integer Division)

Gordon Williams g_will at cyberus.ca
Fri Mar 16 10:39:10 EST 2001


Why do we need a new // operator to do the divide operation.  If we want to
do an integer divide with two reals why wont people just use int(a/b).  For
example:

>>> 5/2
2
>>> int(5.0/2.0)
2
>>>
The only difference with what is described below is a//b will result in a
object of type a while int(a/b) will be of type int.  Does this really need
the use of another operator??

Lets keep it simple.  (And that goes for the other Peps as well)

All these changes make my head spin.  There is more to life than learning
all the fine details in a computer language.  The fewer number of ways to do
something the better.

Regards,

Gordon Williams








// Operator

    A `//' operator which will be introduced, which will call the
    nb_intdivide or __intdiv__ slots.  This operator will be
    implemented in all the Python numeric types, and will have the
    semantics of

        a // b == floor(a/b)

    Except that the type of a//b will be the type a and b will be
    coerced into.  Specifically, if a and b are of the same type, a//b
    will be of that type too.







More information about the Python-list mailing list