What is the output of the expression 7 // 2 in Python?

Prepare for the Leaving Certificate Computer Science Test with a mix of flashcards and multiple choice questions, each designed to enhance learning. Discover tips and resources for success. Ace your exam with confidence!

The expression 7 // 2 in Python uses the floor division operator, which is represented by the double forward slashes (//). This operator divides the left operand by the right operand and returns the largest integer less than or equal to the result of the division.

In this case, dividing 7 by 2 results in 3.5, but because we are using floor division, we take the largest integer that is less than or equal to 3.5, which is 3. Therefore, the output of the expression 7 // 2 is indeed 3.

This output clearly demonstrates how floor division truncates the decimal part of a number, only keeping the integer portion, which is a fundamental characteristic of this operator in Python.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy