Python Arithmetic Operators
Python operators are fundamental for performing mathematical calculations. Arithmetic operators are symbols used to perform mathematical operations on numerical values. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
| Operator | Description | Syntax |
|---|---|---|
| + | Addition: adds two operands | x + y |
| – | Subtraction: subtracts two operands | x – y |
| * | Multiplication: multiplies two operands | x * y |
| / | Division (float): divides the first operand by the second | x / y |
| // | Division (floor): divides the first operand by the second | x // y |
| % | Modulus: returns the remainder when the first operand is divided by the second | x % y |
| ** | Power: Returns first raised to power second | x ** y |
Addition Operator
In Python, + is the addition operator. It is used to add 2 values.
val1 = 2
val2 = 3
# using the addition operator
res = val1 + val2
print(res)
Output:
5Subtraction Operator
In Python, – is the subtraction operator. It is used to subtract the second value from the first value.
val1 = 2
val2 = 3
# using the subtraction operator
res = val1 - val2
print(res)
Output:
-1Multiplication Operator
Python * operator is the multiplication operator. It is used to find the product of 2 values.
val1 = 2
val2 = 3
# using the multiplication operator
res = val1 * val2
print(res)
Output :
6Division Operator
In Python programming language Division Operators allow us to divide two numbers and return a quotient, i.e., the first number or number at the left is divided by the second number or number at the right and returns the quotient.
There are two types of division operators:
- Float division
- Floor division
Float division
The quotient returned by this operator is always a float number, no matter if two numbers are integers. For example:
Example:
print(5/5)
print(10/2)
print(-10/2)
print(20.0/2)
Output
1.0 5.0 -5.0 10.0
Integer division( Floor division)
The quotient returned by this operator is dependent on the argument being passed. If any of the numbers is float, it returns output in float. It is also known as Floor division because, if any number is negative, then the output will be floored. For example:
Example:
print(10//3)
print (-5//2)
print (5.0//2)
print (-5.0//2)
Output
3 -3 2.0 -3.0
Modulus Operator
The % in Python is the modulus operator. It is used to find the remainder when the first operand is divided by the second.
val1 = 3
val2 = 2
# using the modulus operator
res = val1 % val2
print(res)
Output:
1Exponentiation Operator
In Python, ** is the exponentiation operator. It is used to raise the first operand to the power of the second.
val1 = 2
val2 = 3
# using the exponentiation operator
res = val1 ** val2
print(res)
Output:
8Precedence of Arithmetic Operators in Python
Let us see the precedence and associativity of Python Arithmetic operators.
Operator | Description | Associativity |
|---|---|---|
** | Exponentiation Operator | right-to-left |
%, *, /, // | Modulos, Multiplication, Division, and Floor Division | left-to-right |
+, – | Addition and Subtraction operators | left-to-right |
Python Arithmetic Operators – FAQs
What are 7 arithmetic operators in Python?
Python has seven basic arithmetic operators used to perform mathematical operations:
Addition (
+): Adds two numbers. result = 3 + 2 # Output: 5Subtraction (
-): Subtracts one number from another. result = 5 – 2 # Output: 3Multiplication (
*): Multiplies two numbers. result = 3 * 2 # Output: 6Division (
/): Divides one number by another, returning a float. result = 6 / 2 # Output: 3.0Floor Division (
//): Divides one number by another, returning an integer. result = 7 // 2 # Output: 3Modulus (
%): Returns the remainder of a division. result = 7 % 2 # Output: 1Exponentiation (
**): Raises one number to the power of another. result = 3 ** 2 # Output: 9
What is the rule for arithmetic operators in Python?
Arithmetic operators in Python follow the standard mathematical order of operations, also known as BODMAS/BIDMAS rules:
- Brackets
- Orders (exponentiation,
**)- Division and Multiplication (
/,*,//,%)- Addition and Subtraction (
+,-)result = 3 + 2 * 2 ** 2 / 2 - 1 # Output: 6.0
# Explanation: 3 + ((2 * (2 ** 2)) / 2) - 1
# 3 + ((2 * 4) / 2) - 1
# 3 + (8 / 2) - 1
# 3 + 4 - 1
# 7 - 1
# 6.0
What is === in Python?
Python does not have a
===operator. In many other programming languages like JavaScript,===is a strict equality operator that checks both the value and the type. In Python, you use==to check for equality andisto check for identity (if two references point to the same object).
What is arithmetic operator?
An arithmetic operator is a symbol that performs a mathematical operation on one or more operands. The basic arithmetic operators in Python include addition (
+), subtraction (-), multiplication (*), division (/), floor division (//), modulus (%), and exponentiation (**). These operators are used to perform calculations and return a numeric result.


