Explain integer division and modulus.

QuestionsQuestions8 SkillsProPython BasicsDec, 03 2025
0116

Integer Division

Integer division in Python is performed using the // operator. It divides two numbers and returns the quotient without the decimal part (i.e., it truncates towards zero).

Example:

result = 23 // 7  # This will give 3

In this case, 23 divided by 7 equals 3 with a remainder, but only the integer part (3) is returned.

Modulus

The modulus operator % returns the remainder of a division operation. It shows what is left over after performing integer division.

Example:

remainder = 23 % 7  # This will give 2

Here, when 23 is divided by 7, the quotient is 3 and the remainder is 2.

Summary

  • Integer Division (//): Returns the whole number part of the division.
  • Modulus (%): Returns the remainder of the division.

Feel free to ask if you need more examples or further clarification!

0 Comments

no data
Be the first to share your comment!