Home »
Python »
Python Programs
Python Arithmetic Operators: Usage, Types, and Example
Here, we are going to learn about the arithmetic operators in Python and writing a Python program to demonstrate the example for arithmetic operators.
By Shivang Yadav Last updated : April 09, 2023
Python Arithmetic Operators
Following are the Arithmetic Operators (also known as Mathematical Operators) in Python which are used to perform the arithmetic operations.
Types of Arithmetic Operators in Python
Python provides 7 arithmetic operators, they are:
- Addition (+) Operator
- Subtraction (-) Operator
- Multiplication (*) Operator
- Division (/) Operator
- Modulus (%) Operator
- Exponentiation (**) Operator
- Floor division (//) Operator
Arithmetic Operators: Use, Explanation
Operator |
Name |
Description |
Example a=10,b=20 |
+ |
Addition |
Returns the addition of two numbers |
a+b=30 |
- |
Subtraction |
Returns the subtraction of two numbers |
a-b = -10 |
* |
Multiplication |
Returns the product (multiplication) of two numbers |
a*b = 30 |
/ |
Division |
Returns the result of the divide operation of two numbers |
a = 10,b=3 a/b=3.333 |
% |
Modulus |
Returns the remainder of the two numbers |
a=10,b=3 a%b=1 |
** |
Exponent |
Returns the result of exponential operation of two numbers |
a=2, b= 3 a**b = 8 |
// |
Floor division |
Returns the result of the floor division i.e., returns the result without decimal points for positive numbers and returns the floored value if any of the operands is negative |
a=10,b=3 a//b=3 a=10,b=-3 a//b=-4 |
Python Arithmetic Operators Example
# Python program to demonstrate the
# example of arithmetic operators
a = 10
b = 3
# addition
result = a+b
print("a+b :", result)
# subtraction
result = a-b
print("a-b :", result)
# division
result = a/b
print("a/b :", result)
# modulus
result = a%b
print("a%b :", result)
# exponent
result = a**b
print("a**b :", result)
# floor division
result = a//b
print("a//b :", result)
# updating the values of a & b
a = -10
b = 3
print("a:", a, "b:", b)
result = a//b
print("a//b :", result)
Output
a+b : 13
a-b : 7
a/b : 3.3333333333333335
a%b : 1
a**b : 1000
a//b : 3
a: -10 b: 3
a//b : -4
Python Basic Programs »