0
I don't understand the modulo operation. Is the "%" taking a percent or is it just a symbol to indicate modulo?
4 Respostas
+ 3
yes
5%2=1 -> 2*2=4 rem=1
4%2=0 -> 2*2=4 rem=0
7%5=2 -> 5*1=5 rem=2
+ 2
It represents the remainder divided by x?
0
% is the modulo/modulus operator, which returns the remainder of the division that happens. Think:
5 % 3
as:
remainder of 5 / 3
which will lead you to 2. For floor division (// operator), the same applies, but instead of the remainder, you take the whole number part. So 5 // 3 would be 1.
0
To complement answers, it's very useful for simple and complex things :)
For example:
If n % 2 == 0, so n is an even number.
Or also if you generate a fast random integer number between 1 and n (including), with (randNumber % n) + 1