0
What is the function of this "%" operator in python?
2 Respuestas
+ 9
My answer to an older question about the modulo operator:
"
Considering an easy example:
we have two integers: a(5) and b(2).
When we try to divide 5 by 2, then we get an integer that tells us how many times the 2 fits in the 5.
In this example 5/2 is 2;
Now we know that "2" fits at least two times into the 5.
So we look at what we get when we multiply them.
Means: 2*2 = 4.
Now we have the 4, and the last thing that we have to do to find the remainder, is to find the difference between a(5) and the 4.
Means: 5-4 = 1(That's the remainder)
And that's it :D.
Short form is
a=5
b=2
5-((5/2)*2)
5-((2)*2)
5-(4)
5-4 = 1
I hope I could help you."
Link to the question:
https://www.sololearn.com/Discuss/408503/?ref=app
+ 3
It's the modulo operator.
It's used to get the remainder of a divison.
e.g:
10%3 = 1