+ 1
-123//10==-13
Why print(-123//10) will output -13?
3 Answers
+ 3
In Python // performs floor division. It evaluates to the next whole number at or below the division result. The legalistic interpretation of "at or below" leads to unexpected behavior like this when working with negative numbers. The next whole number below -12.3 is -13.
+ 2
Hello, Timofey Ivanenko!
The reasone is because you're dividing a number negative and positive and 123 Ă· 10 = 12.
- 2
For whole number use '/' not '//' as it is for floating point numbers such as 2.3 5.6 etc