DIV and MOD

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Jul 29 10:32:20 EDT 2002


>>>>> "Marcus" == Marcus Vinicius Laranjeira <m.laranjeira at datacraft.com.br> writes:

    Marcus> I need to use some function like DIV (returns the integer
    Marcus> part of a division) and MOD (returns the reminder of a
    Marcus> division) in python, but I don't know how to do that. %
    Marcus> does not work as expected (in this context) and in the
    Marcus> MATH module, I didn't find any kind of function to do such
    Marcus> thing.

When you say it did not work as expected, what did you want, what did
you try, and what did you get? 

Assuming you are working with integers/longs,  then

>>> i = 13
>>> j = 5
>>> i/j     # DIV
2
>>> i%j     # MOD
3

Note that in future pythons, The / operator will no longer be integer
(floor) division.  See http://www.python.org/peps/pep-0238.html.

John Hunter




More information about the Python-list mailing list