View By

Categories

 

What does // mean in python?


It’s floor division. Python docs has very nice documentation on this.


Python3: Mathematical division that rounds down to nearest integer. The floor division operator is //. For example, the expression 11 // 4 evaluates to 2 in contrast to the 2.75 returned by float true division.

>>> 11//4
2
>>> 11/4
2.75

Note that (-11) // 4 is -3 because that is -2.75 rounded downward.

>>> -11//4
-3
>>> -11/4
-2.75

Python2: True division returns round integer in older version of python. Floor division is same.

>>> 11//4
2
>>> 11/4
2 
>>> -11//4
-3
>>> -11/4
-3

Write your first blog & earn!!

Home   |   Contact Us

©2019 by Data Nebulae