In Python, double forward slash (//
) is used for floored division, which means:
- Numbers are divided first, and then;
- 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'>
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.