Articles → Python → Mathematical Operator In Python
Mathematical Operator In Python
Mathematical Operator
- Add operator (+) → This operator is used to add 2 numbers
- Subtract operator (-) → This operator is used to subtract one number from other
- Multiply operator (*) → This operator is used to multiply 2 numbers
- Divide operator (/) → This operator is used to divide 2 numbers
- Modulus operator (%) → This operator returns the remainder when one number is divided by the other. For example, if 10 is divided by 3 then 1 will be the reminder
- Exponent operator (**) → This operator is used to perform exponential calculations on an operand. For example, 32 is written as 3 **2 in Python which is calculated as 2 times 3 i.e., 3 * 3 which is equal to 9
- Floor division (//) → This operator will provide the result of division 2 numbers after removing the decimal. For example, if we divide 11 by 3 then the result of division would be 3.66. After removing the decimal, the result would be 3
Example
operand1 = 3
operand2 = 2
print ("addition:", operand1 + operand2) #addition
print ("subtraction:", operand1 - operand2) #subtraction
print ("multiplication:", operand1 * operand2) #multiplication
print ("division:", operand1 / operand2) #division
print ("modules:", operand1 % operand2) #modules
print ("exponent:", operand1 ** operand2) #exponent
print ("Floor division:", operand1 // operand2) #Floor division
Output