Is there a modulo function in the Python math
library?
Isn't 15 % 4
, 3? But 15 mod 4
is 1, right?
Is there a modulo function in the Python math
library?
Isn't 15 % 4
, 3? But 15 mod 4
is 1, right?
There's the %
sign. It's not just for the remainder, it is the modulo operation.
>>> 15 % 4
3
>>>
The modulo gives the remainder after integer division.
I don't think you're fully grasping modulo. a % b
and a mod b
are just two different ways to express modulo. In this case, python uses %
. No, 15 mod 4
is not 1
, 15 % 4 == 15 mod 4 == 3
.
A = [3, 1, 2, 4]
for a in A:
print(a % 2)
output:
1
1
0
0