Search code examples
python-3.xinteger-division

Python '//' integer division method in classes


How can I add an integer division // method to a class?

I can add a subtraction method like def __sub__(self, other):, so how can I do it with //?

I looked for this online, and couldn't find anything.

Using Python 3.


Solution

  • You're looking for __floordiv__.