Difference between single slash and double slash operator in python

Since the 2.x version is no longer updated, only the 3.x version of python is currently discussed.

1. A single slash (/) indicates division, and regardless of whether the divisor and dividend are integers, the final result is of type float.


2. Double slashes (//) indicate floor division, that is, first divide (/), and then round down (floor). When at least one of the numbers is of type float, the result is of type float; when both numbers are of type int, the result is of type int.


In addition, the floor division floor(x) represents the largest integer not greater than x, so it is not the integer part, such as when x is negative:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325969583&siteId=291194637