Which arithmetic operator in Python is used to perform integer division?
a) /
b) //
c) %
d) **
Answer:
b) //
Explanation:
The //
operator in Python is used for integer division, also known as floor division. It divides two numbers and returns the largest integer less than or equal to the result.
result = 7 // 3 # result is 2
This operator is useful when you need to perform division but are only interested in the whole number part of the quotient, such as when calculating how many full items fit into a container.
Understanding the difference between the /
(regular division) and //
(floor division) operators is crucial for performing accurate calculations, especially when working with integers.