Here is a sample
a = 5 //2
b = int(5/2)
We all know that a = b = 2. My question is
can a // b allways equal int(a/b) ?
I can't find a wrong example...so far
Here is a sample
a = 5 //2
b = int(5/2)
We all know that a = b = 2. My question is
can a // b allways equal int(a/b) ?
I can't find a wrong example...so far
Yes: //
always rounds down, whereas int(...)
rounds towards zero, so they can have different results for negative numbers.
>>> -1 // 2
-1
>>> int(-1 / 2)
0
You can see the difference when you start trying it with negative numbers
>>> -3.5//2
-2.0
>>> int(-3.5/2)
-1
>>>