Modulus
In Python I get this:
But in Java I get this:
Who’s right I don’t know. I guess that you might say that the way Java does it is more correct since no division is taking place. But the way I wanted it to work today at work (coding C++) is the Python way.
>>> 2 % 5
2
>>> -2 % 5
3
>>> 2 % -5
-3
>>> -2 % -5
-2System.out.println(2%5); //2
System.out.println(-2%5); //-2
System.out.println(2%-5); //2
System.out.println(-2%-5); //-2
Zero comments