python / beginner
Snippet
Floor Division and Modulo
Python provides special operators for mathematical division. Floor division (//) rounds the result down to the nearest whole number, while the modulo operator (%) returns only the remainder left over from the division.
snippet.py
1
2
3
4
5
result = 10 // 3remainder = 10 % 3print("Result:", result)print("Remainder:", remainder)
Breakdown
1
result = 10 // 3
Performs floor division, giving 3 instead of 3.33.
2
remainder = 10 % 3
Calculates the remainder of 10 divided by 3, which is 1.