+ 1
Can someone explain how the % thing works
Can someone explain how the % thing works
3 Respuestas
+ 13
I found this hard to learn. It's important though. These answers are helpful! I finally fired up Python and just started throwing modulus examples at it...might be helpful for some people to do that..
+ 7
% or Modulo works by returning the remainder of division between 2 numbers. For example. x= 3%2, so x = 1 three divided by two leaves a remainder of one. Modulo returns the remainder only. remember that. Also Modulo only works with whole int numbers not floats. otherwise there would be no remainder
+ 7
Worth to add that it might be working somewhat counterintuitively for negative numbers:
19 % 5 = 4
-19 % 5 = 1
-19 % -5 = -4
19 % -5 = -1