What's "//" Used For in Python?

Find out what double forward slash does in Python

In Python, double forward slash (//) is used for floored division, which means:

  1. Numbers are divided first, and then;
  2. Rounded down (or floored) to the nearest integer.

Using x // y is equivalent to floordiv(x, y).

You can draw the comparison between true division and floored division in the following examples:

// floored division
num = 9 // 5

print(num) # 1
print(type(num)) # <class 'int'>
// division
num = 9 / 5

print(num) # 1.8
print(type(num)) # <class 'float'>

Hope you found this post useful. It was published . Please show your love and support by sharing this post.