-4

I am not able to understand how is 10%-3 -2 in python? I am a beginner who just started learning python. Please explain

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271

1 Answers1

-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
  • 2
    The 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