The syntax for modulus operator is
Where a,b and c are a numeric value.
Let’s take a look at a python code example
You can even use float point numbers in python to get their remainders.
Let’s take a look to see how the modulus calculates the remainder
All this calculation is required if you don’t use the modulus operator (%).
Here is a programming example that can help you understand better how the operator works.
To find the leap year
year = int(input("Enter a year: ")) if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print(" leap year",year) else: print("not a leap year",year) else: print("leap year",year) else: print("not a leap year",year)
In conclusion, a modulus operator (%) in Python is a very handy and unique arithmetic operator that can become part of very tricky problems and solve them accordingly. You can click here for more details