I am not able to understand how is 10%-3 -2 in python? I am a beginner who just started learning python. Please explain
Asked
Active
Viewed 51 times
1 Answers
-2
It is a question of math, the evaluation is like this, (10) % (-3), and if you input this into any calculator, it will give you -2. Try typing 10 modulo -3 on Google and see the result

Ahmet-Salman
- 194
- 8
-
2The rules aren't that strictly defined with negative operands. [It can just as easily produce `1`](https://tio.run/##Sy4o0E1PTv7/XzkzLzmnNCVVwaa4JCUzXy/Djiszr0QhNzEzT0NToZpLAQgKioBCaRpKqikxeUo6CoYGCqoKusaa1ly1//8DAA "C++ (gcc) – Try It Online"). Python has specifically defined modulus to work this way, that's all. – ShadowRanger Feb 12 '23 at 14:25