There are two different division operators in Python. See which one you should use and when.
You may be confused on having two types of division operators in Python:
/ – this is regular division operator
// – this is floor division operator (aka integer division)
Let’s see the difference by examples:
print(f'Result of regular division for 5/2: ') print(5/2) print(f'Result of floor division for 5//2:') print(5//2) print(f'Result of floor division for -5//2:') print(-5//2)
AS you can see 5/2 = 2.5 but 5//2 equals 2. This is because the result of regular division is a float but floor division returns an integer.
Hint: -5//2 equals -3 because integer division always rounds down. You need to remember about that to avoid confusion.