+ 1

-123//10==-13

Why print(-123//10) will output -13?

8th Dec 2021, 8:50 PM
Timofey Ivanenko
Timofey Ivanenko - avatar
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.
9th Dec 2021, 12:43 AM
Brian
Brian - avatar
+ 2
Hello, Timofey Ivanenko! The reasone is because you're dividing a number negative and positive and 123 Ă· 10 = 12.
8th Dec 2021, 9:31 PM
CGO!
CGO! - avatar
- 2
For whole number use '/' not '//' as it is for floating point numbers such as 2.3 5.6 etc
10th Dec 2021, 7:50 PM
elly paul
elly paul - avatar