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 variablexis5
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules