Editor settings

General settings

Save settings

Learn to program with Python

Floor division in Python #

Floor division is performed using the double forward slash operator //. It returns the quotient of a division, but rounded down to the nearest integer. If both numbers are integers, the result will be type int, but if one or both of the numbers are floats, the result will be type float.

For example:

print(7 // 2) # Output: 3

print(10 // 3) # Output: 3

print(10.0 // 3) # Output: 3.0

print(7 // 3.0) # Output: 2.0

Exercise #

  • Change the / to // so that the value of variable x is 5
Output will be displayed here