This is because in JavaScript % is the "remainder" operator while in Python it is the "modulus" (clock math) operator. You can get the explanation directly from GvR: Edit - dahiya_boy In Java and iOS -11 % 5 = -1 whereas in python and ruby -11 % 5 = 4. Well half of the reason is explained by the Paulo Scardine, and rest of the explanation is ...
0 Modulus operator gives you the result in 'reduced residue system'. For example for mod 5 there are 5 integers counted: 0,1,2,3,4. In fact 19=12=5=-2=-9 (mod 7). The main difference that the answer is given by programming languages by 'reduced residue system'.
I am new to programming, and I chose to learn Python, and I came across this operator (%) called modulus, but I don't understand it, can some explain it to me in more detail!
Exactly how does the % operator work in Python, particularly when negative numbers are involved? For example, why does -5 % 4 evaluate to 3, rather than, say, -1?
I have a "modulus" as a long string of numbers that is obtained from doing the following: private_key = rsa.generate_private_key (public_exponent=65537, key_size=2048) modulus = private_key.
What the % in python actually is is a modulus operator where x % y gives the remainder of x / y. In this case, what happened was that 75 / 4 is 18, with a remainder of 3, which is why 100 - 3 = 97. Do not try to multiply the percentages, it's a common mistake.