N
N
nihi1ist2021-06-13 14:25:02
Python
nihi1ist, 2021-06-13 14:25:02

How to understand the principle of working with minuses in Python?

I am watching a lecture by Timofey Khiryanov. And I do not understand the logic of this part of his lectures:

(-12) // 5 = -3
(-12) % 5 = 3
(-11) // 10 = -2
(-11) % 10 = 9

I understand that this is more related to mathematics. I would be grateful for a simple explanation or a link to a simple explanation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-06-13
@nihi1ist

https://ru.wikipedia.org/wiki/Division_with_remainder

Remainder sign The remainder
operation in programming languages ​​can return a negative result (for a negative dividend or divisor). There are two options:
The sign of the remainder is the same as the sign of the dividend: the incomplete quotient rounds towards zero.
The sign of the remainder is the same as the sign of the divisor: the partial quotient rounds to -∞.

In Python, the second option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question