What will be the output of print(5 // 2)?

Master Python with the PCAP Certification! Explore interactive quizzes and detailed explanations to ensure your exam success. Gain confidence and get certified!

The output of the expression print(5 // 2) is indeed 2, which corresponds to integer division in Python. The // operator performs floor division, which divides the first operand by the second and then rounds down to the nearest whole number.

In this case, when you divide 5 by 2, you get 2.5 as the division result. However, since the floor division operator is used, Python takes the integer part of the result and discards the decimal portion, giving you 2.

This is a fundamental aspect of Python's division behavior, distinguishing between regular division (which produces a floating-point number) and floor division (which produces an integer). Understanding this difference is crucial for effective programming in Python, especially when working with integer and floating-point operations.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy