In this Post, we will study how modulus is calculated in Python. Before Proceeding, first, see what is the modulus?
modulus is mathematically term, which is used to find the remainder when we divide two number. e.g. when one number says number1=10, and second number number2=2, when we do number1/number2 then the remainder left will be 0. so we can say modulus of 10 and 2 is 0, as 2 fully divided the 10.
Modulus in Python
Modulus is calculated with the modulus operator
% in Python.
Let’s take one example to see how modulus works.
# Program to find modulus try : #Take first number from user, and convert it into number a=input("Enter first number :") a=int(a) #Take second number from user, and convert it into number b=input("Enter second number :") b=int(b) c= a%b print("Modulus of",a," and",b,"is :",c) except : print("something wrong... Plesae try again..")
Enter first number :34 Enter second number :4 Modulus of 34 and 4 is : 2
- Above is an example of finding the modulus of two numbers.
- where a and b are two numbers.
%an operator is used to finding the modulus of two numbers.